Thursday, June 13, 2013

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 to fill the form and not upload any existing documents to the document libraries in a particular site. So wanted to disable Upload Document button from SharePoint ribbon.
hide sharepoint ribbon button

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.
sharepoint hide ribbon items
2. Add a new "Empty Element" item to the project. This will create a Feature with Elements.xml file.
hide sharepoint ribbon tab

3. Update the Elements.xml file with below content.

 <?xml version="1.0" encoding="utf-8"?>
  <Elements xmlns="">
            Location="Ribbon.Documents.New.AddDocument" />
hide a ribbon button in sharepoint 2010

4. Now, Go to Feature designer, Name the Feature Title & Description. Specify the scope as Web and Include the Element to the feature.
sharepoint 2010 hide button from ribbon

5. Deploy the feature and see the result in action.
hide a ribbon button in sharepoint 2010
Here the Location is the key. For all available location values, refer MSDN:

Tips: You can also use IE Toolbar/Firebug to get the location ID! (Take the text till - Hyphen )
sharepoint ribbon hide tab

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 its possible to target custom action to List types, Content Types, File Types, There is no way to target on specific list declaratively! 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("http://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 = @" 
                        <CommandUIDefinition Location=""Ribbon.ListItem.New"">

To remove the custom action use this code:
      using (SPSite site = new SPSite(""))
            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")

Hide Ribbon Button by CSS:
We can hide ribbon buttons using CSS also. Refer this post for more info: How to Disable Multiple File Upload in SharePoint

Microsoft KB:

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.

Check out these SharePoint products:

No comments :

Post a Comment

Please Login and comment to get your questions answered!

You might also like:

Related Posts Plugin for WordPress, Blogger...