Hide Ribbon buttons sharepoint 2010 programmatically

Follow Us :

In this post you will learn how to hide ribbon, ribbon button and ribbon groups using SharePoint 2010 object model.

You can use the below code in a user control and add it to the Master Page of your current site.

Hide Ribbon(whole Ribbon)

SPRibbon ribbon = SPRibbon.GetCurrent(this.Page);
if (ribbon != null)
{
ribbon.TrimById(“RibbonGroupId”);
}
What is this RibbonGroupId ? Well the idea is to hide all the groups in the ribbon and the whole ribbon will be trimmed. To get the id’s for ribbon groups, Open the file C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\GLOBAL\XML\CMDUI.XML in Internet Explorer and search for “Ribbon.EditingTools.CPEditTab.Groups

The sub-nodes are the ones you’re interested in – a collection of GROUP nodes. The groups should look familiar – they correlate to the panes on the ribbon pane :

o Ribbon.EditingTools.CPEditTab.EditAndCheckout
o Ribbon.EditingTools.CPEditTab.Clipboard
o Ribbon.EditingTools.CPEditTab.Font
o Ribbon.EditingTools.CPEditTab.Paragraph
o Ribbon.EditingTools.CPEditTab.Styles
o Ribbon.EditingTools.CPEditTab.Layout
o Ribbon.EditingTools.CPEditTab.Markup

so to trim the while ribbon just use the ribbon groups like below
for e.g . ribbon.TrimById(“Ribbon.EditingTools.CPEditTab.EditAndCheckout”);

Side Note : You can add this code in a custom web user control and the control to the master page.

Hide a single Button on Ribbon –

Copied from our Forum Post Here the goes goes as below :
public void HideRibbonButton()
{
//if this is a System.Web.UI.Page
SPRibbon ribbon = SPRibbon.GetCurrent(this);
ribbon.TrimById(“Ribbon.DocLibListForm.Edit.Actions.DeleteItem”);
}
Another option is to create “HideCustomAction” feature that will hide the ribbon button from the site\ site collection where the feature will be activated. See an example – HideCustomAction

Hide group –

As seen in the first scenario you can use groupid to hide the ribbon groups like below
ribbon.TrimById(“Ribbon.EditingTools.CPEditTab.EditAndCheckout”);

Also see the related forum thread SharePoint 2010 hide ribbon group on document library programmatically


Tags: SharePoint 2010