Welcome to EMC Consulting Blogs Sign in | Join | Help

roberto.ortega

Customizing the SharePoint Ribbon per Document Library

The Problem

I came across a situation where I needed to remove certain ribbon buttons for certain document libraries. I could have gone the route of adding code to the master page either on the server side or javascript that would run on the client side. Since the document libraries would be numerous and since that sort of one-off page modification would not work well when a list view web part was dropped on a random page anywhere on the site.

The Solution

I was able to solve my problem by creating a SharePoint solution (WSP) with a custom list template that would specify a customize the ribbon for any document library of that type. I would then only have to create my document libraries from that type and I would get my customized ribbon regardless of whether I was on a list view page or any other page with a list view web part.

Feature.xml

<?xml version="1.0" encoding="utf-8" ?>
<Feature Id="f891e3ae-2983-4e7e-961f-c18e4f915da5"
         Title="Hide Ribbon Buttons"
         Description="Hides ribbon buttons for the custom list type"
         Version="1.0.0.0"
         Scope="Web"
         xmlns="http://schemas.microsoft.com/sharepoint/">
  <ElementManifests>
    <ElementManifest Location="Manifest.xml" />
  </ElementManifests>
</Feature>

Manifest.xml

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <CustomAction
    Id="HideRibbonButtons"
    Location="CommandUI.Ribbon"
    RegistrationType="List"
    RegistrationId="0x0101000BB3F82E2A624B77833C28045F765D7B">
    <CommandUIExtension>
      <CommandUIDefinitions>
        <CommandUIDefinition Location="Ribbon.Library.Actions.OpenWithExplorer" />
        <CommandUIDefinition Location="Ribbon.Documents.New.AddDocument.Upload.Upload" />
        <CommandUIDefinition Location="Ribbon.Documents.New.AddDocument.Upload.UploadMultiple" />
        <CommandUIDefinition Location="Ribbon.Documents.New.NewDocument" />
        <CommandUIDefinition Location="Ribbon.Documents.New.AddDocument" />
        <CommandUIDefinition Location="Ribbon.Documents.New.UploadDocument" />
      </CommandUIDefinitions>
    </CommandUIExtension>
  </CustomAction>
</Elements>

Additional Notes

This same technique can be used to modify the URLs, the text or the icon for them. That still leaves the issue of the "+ Add Document" link that the list view web part produces. Unfortunately, for that it seems that we have to resort to client-side script. SharePoint does not provide a way to globally modify the output of the list view web part in this respect for a particular document library, or type of document library. Furthermore, the link to upload.aspx appears to be hard coded in the web part.

Published 17 December 2011 17:23 by roberto.ortega

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

No Comments

Leave a Comment

(required) 
(optional)
(required) 
Submit
Powered by Community Server (Personal Edition), by Telligent Systems