none
Hide/disable ribbon items

    Question

  • I need to hide (or at least disable) a button in the ribbon of a certain list. I know that in case of the "new" button this would be possible using permissions. But what about the other items.

    Initially I tried the <HideCustomControl> element but this removes the button on every ribbon across the whole site.

    My second approach would be javascript, but apparently the DOM elements get created when the user first opens the tab. Therefore I can't modify the elements when the page loads.

    Any ideas?

    Wednesday, May 12, 2010 2:30 PM

Answers

  • In your code make a reference to Microsoft.SharePoint.WebControls and then Microsoft.Web.CommandUI (GAC). Then on your page load or rendering in your webpart you can try the following code using the SPRibbon.TrimById method. I am unsure of the strings you need for the the buttons you are trying to hide. Which buttons are you trying to hide?

     public void HideRibbonItem()
     {
          //if this is a System.Web.UI.Page
          SPRibbon ribbon = SPRibbon.GetCurrent(this);
          ribbon.TrimById("Ribbon.ListItem.New.NewFolder");
          
     }

    certdev.com
    • Marked as answer by matthias eder Tuesday, May 18, 2010 11:53 AM
    Tuesday, May 18, 2010 3:46 AM

All replies

  • Hi Matthias,

    Chris O'Brien has some great posts here about manipulating the ribbon: http://www.sharepointnutsandbolts.com/2010/01/customizing-ribbon-part-1-creating-tabs.html

    He does not show an example of disabling a button and the documentation around SP.Ribbon.PageManager is far from complete: http://msdn.microsoft.com/en-us/library/ff410969(v=office.14).aspx, but hopefully it might point you in the right direction.

    Regards,


    Brian C | Blog Site
    Friday, May 14, 2010 8:14 AM
  • Hi Brian.

    I think I read Chris' posts about 5 times now, but as you said, there is no hint about hiding ribbon controls. For now I'm going with permissions and throwing error messages when using the controls, but I definitely keep looking for a way to hide/disable ribbon controls.

    Thank you though,

    Monday, May 17, 2010 7:24 AM
  • In your code make a reference to Microsoft.SharePoint.WebControls and then Microsoft.Web.CommandUI (GAC). Then on your page load or rendering in your webpart you can try the following code using the SPRibbon.TrimById method. I am unsure of the strings you need for the the buttons you are trying to hide. Which buttons are you trying to hide?

     public void HideRibbonItem()
     {
          //if this is a System.Web.UI.Page
          SPRibbon ribbon = SPRibbon.GetCurrent(this);
          ribbon.TrimById("Ribbon.ListItem.New.NewFolder");
          
     }

    certdev.com
    • Marked as answer by matthias eder Tuesday, May 18, 2010 11:53 AM
    Tuesday, May 18, 2010 3:46 AM
  • Thanks Steve. That's exactly what I was looking for.

    I allready found the available IDs for the ribbon items here: http://msdn.microsoft.com/de-de/library/ee537543(en-us,office.14).aspx

    Tuesday, May 18, 2010 11:55 AM
  • For the benefit of others, here is the English site link that was shared by Matthias Eder in the above post:

    http://msdn.microsoft.com/en-us/library/ee537543(en-us,office.14).aspx


    Thanks & Regards,
    Kamlesh | Blog | Twitter | Posting is provided "AS IS" with no warranties, and confers no rights.
    Tuesday, May 18, 2010 12:06 PM
  • In my case I wanted to hide the new button and the hide all documents button, 

    I did it like this:

     protected void Page_Load(object sender, EventArgs e)
        {
    
            SPRibbon ribbon = SPRibbon.GetCurrent(this.Page);
            //IDS for the ribbon are found at "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\GLOBAL\xml\CMDUI.XML"
            ribbon.TrimById("Ribbon.Documents.New.NewDocument");
            ribbon.TrimById("Ribbon.Documents.New.AddDocument.Menu.Upload.UploadMultiple");
    
        }
    

    the buttons are declared inside an xml file at C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\GLOBAL\xml\CMDUI.XML

    Thursday, December 09, 2010 10:24 AM
  • Hi,

    I had the exact same issue myself and got around the issue with a combination of CSS and jQuery. Have a look at my solution and see what you think:

    http://blog.lekman.com/2011/05/hiding-inactive-ribbon-commands-in.html

     

    Hope this helps!


    Tobias Lekman, SharePoint Architect at Sogeti > http://lekman.com | http://www.linkedin.com/in/lekman | http://twitter.com/tobiaslekman | http://blog.lekman.com
    Wednesday, May 25, 2011 7:31 AM
  • Hi,

    How to hide the New Document, Upload Document, which appears for a document library in the Ribbon using CSS ?

    I have tried this:

    In the content editor web part - Html Mode:

    [CODE]

    <style type="text/css">
    .New.Documents#Ribbon {
     DISPLAY: none !important
    }</style>

    [/CODE]

    But I can still the New Document/Upload Document option visible in the ribbon

    Thank you.

    Tuesday, June 07, 2011 12:29 PM
  • Hi Steve,

    Can the above code be used in web part, and then added to a web part page.

    Thursday, June 16, 2011 6:16 AM
  • any idea of how to hide the ribbon button programatically,??

     

    i just created a custom button on my list's display forms Ribbon. now i want to hide it programatically. is this possible?

     

    thanks...

    Saturday, September 10, 2011 5:54 AM
  • HI,

    Please try this:

    create a web part, with the below code and add this web part in the list.

    [CODE]

          SPRibbon ribbon = SPRibbon.GetCurrent(this.Page);

          ribbon.TrimById("ButtonId");

    [/CODE]

    Saturday, September 10, 2011 7:43 AM
  • HI,

    Please try this:

    create a web part, with the below code and add this web part in the list.

    [CODE]

          SPRibbon ribbon = SPRibbon.GetCurrent(this.Page);

          ribbon.TrimById("ButtonId");

    [/CODE]

    but my button is a custom ribbon button, what value of ID should i use ?
    Saturday, September 10, 2011 8:34 AM
  • Hi,

    In the elements.xml file, what is the id you gave for the custom button.

    Saturday, September 10, 2011 9:23 AM
  • no, i created the button using sharepoint designer 2010
    Saturday, September 10, 2011 9:43 AM
  • ok..

    Try to import that in Visual studio and then you would get the elements.xml file. In the elements.xml, you may get the ID of the button.

    I am not sure, if this works -  after you view the list in IE, can you check if the button is rendered, and if yes, check the view source. Search for the button. There would be an ID associated with it.

    Saturday, September 10, 2011 10:07 AM
  • thanks a lot Venkatzeus, but are you sure it will be same on my TEST aswellas LIVE machine.?
    Saturday, September 10, 2011 10:13 AM
  • Hi,

    The contentplaceholderid would be same.

    Search for ctl00_PlaceHolderMain_(followed by the button)

    Saturday, September 10, 2011 10:35 AM
  • What if you want to disable it instead of hide it?  I'd rather it still be visible.

    Saturday, September 17, 2011 2:18 PM
  • Thanks for the post..

    However, it looks like not all buttons can be removed in this way from the SharePoint 2010 ribbon. I have a publishing site and i am trying to remove the 'Unpublish' button under Submit in 'Publish' tab but have been unsuccessful using the above mentioned method. There are other ribbon buttons that are not removed in this way as well.

    Is there a list of all the buttons that cannot be removed? or another way to remove these buttons?
    Jatin
    Monday, January 16, 2012 6:32 AM
  • Hi, 

    The code above can be used on the same page as the list, What if it needs to be on page load?

    Tuesday, April 10, 2012 9:57 AM