How to Hide SharePoint 2010 Ribbon Tab – Group – Button – Menu?
How to hide Ribbon Tab – Group – Button – Menu in SharePoint 2010? But why? Because the requirement is: Users fill the form and not upload any existing documents to the document libraries on a particular site. So wanted to disable the Upload Document button from the SharePoint ribbon.
Solution:
Override the existing SharePoint 2010 Ribbon Tab/Group/Button/Menu by creating an empty CommandUIDefinition!
Steps in Detail:
1. Create an empty SharePoint 2010 farm solution project in Visual Studio 2010. Give it a name. Say, Crescent.TeamSites.HideUploadButton.
2. Add a new “Empty Element” item to the project. This will create a Feature with Elements.xml file.
3. Update the Elements.xml file with below content.
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="https://schemas.microsoft.com/sharepoint/">
<CustomAction
Id="RemoveRibbonButton"
Location="CommandUI.Ribbon">
<CommandUIExtension>
<CommandUIDefinitions>
<CommandUIDefinition
Location="Ribbon.Documents.New.AddDocument" />
</CommandUIDefinitions>
</CommandUIExtension>
</CustomAction>
</Elements>
4. Now, Go to Feature designer, Name the Feature Title & Description. Specify the scope as Web and Include the Element in the feature.
5. Deploy the feature and see the result in action.
Here the Location is the key. For all available location values, refer MSDN: https://msdn.microsoft.com/en-us/library/ee537543%28v=office.14%29.aspx
Tips: You can also use IE Toolbar/Firebug to get the location ID! (Take the text till – Hyphen )
Hiding SharePoint 2010 Ribbon Tabs, Groups, Button Menus
The above method applies when you want to hide button menus from the Ribbon.
- E.g. Hide “Upload Multiple Documents” Menu link under “Upload” button, specify the location as: Ribbon.Documents.New.AddDocument.Menu.Upload.UploadMultiple
- To Hide Ribbon Tabs, E.g. Hide Documents tab in document library ribbon, the location should be “Ribbon.Document“.
- Similarly to hide Ribbon Tab Button Groups, E.g. “New” group in SharePoint Ribbon, specify the location as: Ribbon.Documents.New
How to Hide Ribbon Tab – Group – Button – Menu on a Particular List?
While it’s possible to target custom action to List types, Content Types, File Types, There is no way to target on specific list declarative! So, we can get it done programmatically. Here is how to hide ribbon buttons in SharePoint 2010 programmatically:
static void Main(string[] args)
{
using (SPSite site = new SPSite("https://sharepoint.crescent/"))
using (SPWeb web = site.OpenWeb())
{
//Get the "Projects" List
SPList list = web.Lists.TryGetList("Projects");
if (list != null)
{
var action = list.UserCustomActions.Add();
action.Location = "CommandUI.Ribbon";
action.Sequence = 50;
action.Title = "Hide Upload Button from Ribbon";
action.CommandUIExtension = @"
<CommandUIExtension><CommandUIDefinitions>
<CommandUIDefinition Location=""Ribbon.ListItem.New"">
</CommandUIDefinition>
</CommandUIDefinitions>
</CommandUIExtension>";
action.Update();
}
}
}
To remove the custom action use this code:
using (SPSite site = new SPSite("https://sharepoint.crescent.com/"))
using (SPWeb web = site.OpenWeb())
{
//Get the "Projects" List
SPList list = web.Lists.TryGetList("Projects");
if (list != null)
{
foreach (SPUserCustomAction action in list.UserCustomActions)
{
if (action.Title == "Hide Upload Button from Ribbon")
{
action.Delete();
break;
}
}
}
}
Hide Ribbon Button by CSS:
We can hide ribbon buttons using CSS also. Refer to this post for more info: How to Disable Multiple File Upload in SharePoint?