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("<CommandUIExtension>");
newurl.AppendLine("     <CommandUIDefinitions>");
//Provide Location ID to hide the button
newurl.AppendLine("        <CommandUIDefinition Location=\"Ribbon.Documents.New.NewFolder\">");
newurl.AppendLine("        </CommandUIDefinition>");
newurl.AppendLine("    </CommandUIDefinitions>");
newurl.AppendLine("</CommandUIExtension>");

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

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.

Enjoy!!!

Comments

Popular Posts

SharePoint Interview Questions and Answers

Download Infopath Form Templates

How to get current logged user information using JavaScript ?

Steps to set Form based authentication (FBA) for SharePoint 2010

SharePoint Interview Questions and Answers II

Get List Items - JavaScript

Change Language for current user with JSOM in SharePoint Online

Cross Site List Rollup Web Part for SharePoint 2010

Hide Recently Modified Items

SharePoint 2010 CSS Chart