Showing posts with label Hide Ribbon buttons. Show all posts
Showing posts with label Hide Ribbon buttons. Show all posts

Thursday, August 23, 2012

Hide buttons control from ribbon for specific list

Hi ,

I want to hide "New Folder" button from ribbon of my library "Shared Documents" for site "SP2010-01".


To hide this button from ribbon for a Shared Documents, You must write this code :

using (SPSite site = new SPSite("http://SP2010-01"))
using (SPWeb web = site.OpenWeb())
SPList list = web.Lists.TryGetList("Shared Documents");
web.AllowUnsafeUpdates = true;
SPUserCustomAction actionView = list.UserCustomActions.Add();

StringBuilder newurl = new StringBuilder();
newurl.AppendLine("     <CommandUIDefinitions>");
//Provide Location ID to hide the button
newurl.AppendLine("        <CommandUIDefinition Location=\"Ribbon.Documents.New.NewFolder\">");
newurl.AppendLine("        </CommandUIDefinition>");
newurl.AppendLine("    </CommandUIDefinitions>");

actionView.Location = "CommandUI.Ribbon";
actionView.Title = "RemoveNewFolderButton";
actionView.CommandUIExtension = newurl.ToString();

web.AllowUnsafeUpdates = true;

After deployment of this code, you will see :


This code will hide "New Folder" button from "Shared Documents" library from "SP2010-01" site.

For more location ID visit site.