How To: Disable “New Folder” button in the SharePoint 2010 Ribbon via Feature

Tags: Technical

I dug through this thanks to a post on the MSDN forums… thought I would copy the results of my findings here.

Basically the use case is: for some reason you want to enable Folders within lists and document libraries, but maybe you don’t want users to be able to create the Folders.  (We won’t talk about why Folders are generally a bad idea in SharePoint Lists and Document Libraries Smile ).  But lets say that your folders are being created some other way… programmatically or via Workflow.

Its pretty simple to write a custom action that removes the new folder button for any List… it looks something like this:

<CustomAction
    Id="Remove.ListItem.NewFolder"
    Location="CommandUI.Ribbon">
    <CommandUIExtension>
      <CommandUIDefinitions>
        <CommandUIDefinition
          Location="Ribbon.ListItem.New.NewFolder" />
      </CommandUIDefinitions>
    </CommandUIExtension>
</CustomAction>

But what if you also want to disable the New Folder Button for Document Libraries?  In this case you need a similar custom action as above, but you a different Location and to Register it directly to the Document Content Type:

<CustomAction
    Id="Remove.Document.NewFolderButton"
    Location="CommandUI.Ribbon" RegistrationId="0x0101" 
    RegistrationType="ContentType">
    <CommandUIExtension>
      <CommandUIDefinitions>
        <CommandUIDefinition
          Location="Ribbon.Documents.New.NewFolder" />
      </CommandUIDefinitions>
    </CommandUIExtension>
</CustomAction>

Note the RegistrationType and RegistrationId—0x0101 is the ContentTypeId for the generic “Document” content type.

So, if you wanted to disable the New Folder Button for all Lists and Libraries, you’d have an elements definition in your feature like so:

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <CustomAction
    Id="Remove.ListItem.NewFolder"
    Location="CommandUI.Ribbon">
    <CommandUIExtension>
      <CommandUIDefinitions>
        <CommandUIDefinition
          Location="Ribbon.ListItem.New.NewFolder" />
      </CommandUIDefinitions>
    </CommandUIExtension>
  </CustomAction>
  <CustomAction
    Id="Remove.Document.NewFolderButton"
    Location="CommandUI.Ribbon" RegistrationId="0x0101" 
    RegistrationType="ContentType">
    <CommandUIExtension>
      <CommandUIDefinitions>
        <CommandUIDefinition
          Location="Ribbon.Documents.New.NewFolder" />
      </CommandUIDefinitions>
    </CommandUIExtension>
  </CustomAction>
</Elements>
Add a Comment