SharePoint Ribbon customization for a specific content type

I wanted to utilize the new SharePoint 2010 Ribbon for performing a custom action on items in a custom list.  The list contained items that were of a custom content type (lots of custom work going on).  With some great posts from Chris O’Brien and MSDN, I found all the XML needed to accomplish the task.  I also took advantage of the Custom Tab, Button Groups and Notifications while I was at it.

A couple of things to note when targeting the content type for ribbon customization.  The content type that was used for the CustomAction was created through code, so I didn’t have the ID at design time to add to the Ribbon customization.  I deployed the content type first, looked up the content type ID (this can be done quickly by viewing the properties of the CT and looking at the ID in the URL).  Once I had that ID, I was able to set the CustomAction RegistrationId to the ID and the RegriatrationType to “ContentType.”  Also, I only wanted the button to be active when one or more items were selected.  I modified the EnabledScript function to make that happen.

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="">
  RegistrationType="ContentType" >
        <CommandUIDefinition Location="Ribbon.Tabs._children">
          <Tab Id="SharePoint.Ribbon.SohemasTab" Title="Sohema Commands" Description="Sohema Workflow Commands" Sequence="501">
            <Scaling Id="SharePoint.Ribbon.SohemasTab.Scaling">
              <MaxSize Id="SharePoint.Ribbon.SohemasTab.SohemaActionGroup.MaxSize"
              <Scale Id="SharePoint.Ribbon.SohemasTab.SohemaActionGroup.Scaling.SohemasTabScaling"
                                   Size="OneLarge" />
            <Groups Id="SharePoint.Ribbon.SohemasTab.Groups">
                              Description="Contains Sohema Action items"
                              Title="Perform Sohema Actions"
                <Controls Id="SharePoint.Ribbon.SohemasTab.SohemaActionGroup.Controls">
                  <Button Id="Ribbon.Documents.New.SohemaPushToCSVRibbonButton"
                    Alt="Push selected item(s) to CSV"
                    LabelText="Push Sohema(s) To CSV"
                    TemplateAlias="PushSohema" />
        <CommandUIDefinition Location="Ribbon.Templates._children">
          <GroupTemplate Id="Ribbon.Templates.OneLargeExample">
            <Layout Title="OneLarge" LayoutTitle="OneLarge">
              <Section Alignment="Top" Type="OneRow">
                  <ControlRef DisplayMode="Large" TemplateAlias="PushSohema" />
            var notificationId = SP.UI.Notify.addNotification('Processing Sohemas');"
                    EnabledScript="javascript:function moreThanOneEnabled()
              var items = SP.ListOperation.Selection.getSelectedItems();
              var ci = CountDictionary(items);
              return (ci > 0);
            moreThanOneEnabled(); " />

  1. #1 by Dee on July 7, 2011 - 12:55 pm

    After a long search, i found only on your blog abt EnabledScript.thanks..

  2. #2 by Dee on July 7, 2011 - 1:28 pm

    My button on the ribbon is always active irrespective of the content type.Should it be done on the enabledscript?I thought registrationtype=contenttype takes care of it.

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: