Friday, November 19, 2010

Custom Ribbon Actions in SharePoint 2010 - Elements.xml

Custom action to add a Ribbon button in the Display Form of a SharePoint List:

<CustomAction Description="Prints a single List Item" Title="Print List Item" Id="{055c63b4-58d8-4b4a-a366-70f69257b491}" Location="CommandUI.Ribbon.DisplayForm" RegistrationId="100" RegistrationType="List" Sequence="0" Rights="ViewListItems" xmlns="http://schemas.microsoft.com/sharepoint/">
    <UrlAction Url="~site/_layouts/PrintListItem/PrintListItem.aspx?List={ListId}&amp;ID={ItemId}" />
    <CommandUIExtension xmlns="http://schemas.microsoft.com/sharepoint/">
      <CommandUIDefinitions>
        <CommandUIDefinition Location="Ribbon.ListForm.Display.Manage.Controls._children">
          <Button Id="{C75857A4-C0BC-439A-813A-A1DCC885A14A}" Command="{06000B27-86BB-4203-AF44-29F61FDA678D}" Image32by32="~site/_layouts/Icon/PrintIcon.jpg" Image16by16="~site/_layouts/Icon/PrintIcon.jpg" Sequence="0" LabelText="Print List Item" Description="Prints a Single List Item" TemplateAlias="o1" />
        </CommandUIDefinition>
      </CommandUIDefinitions>
      <CommandUIHandlers>
        <CommandUIHandler Command="{06000B27-86BB-4203-AF44-29F61FDA678D}" CommandAction="~site/_layouts/PrintListItem/PrintListItem.aspx?List={ListId}&amp;ID={ItemId}" />
      </CommandUIHandlers>
    </CommandUIExtension>
  </CustomAction>

Custom action to add a Ribbon button in the Display Form of a SharePoint Task List:

<CustomAction Description="Prints a single List Item" Title="Print List Item" Id="{055c63b4-58d8-4b4a-a366-70f69257b491}" Location="CommandUI.Ribbon.DisplayForm" RegistrationId="107" RegistrationType="List" Sequence="1000" Rights="ViewListItems" xmlns="http://schemas.microsoft.com/sharepoint/">
    <UrlAction Url="~site/_layouts/PrintListItem/PrintListItem.aspx?List={ListId}&amp;ID={ItemId}" />
    <CommandUIExtension xmlns="http://schemas.microsoft.com/sharepoint/">
      <CommandUIDefinitions>
        <CommandUIDefinition Location="Ribbon.ListForm.Display.Manage.Controls._children">
          <Button Id="{C75857A4-C0BC-439A-813A-A1DCC885A14A}" Command="{06000B27-86BB-4203-AF44-29F61FDA678D}" Image32by32="~site/_layouts/Icon/PrintIcon.jpg" Image16by16="~site/_layouts/Icon/PrintIcon.jpg" Sequence="1000" LabelText="Print List Item" Description="Prints a Single List Item" TemplateAlias="o1" />
        </CommandUIDefinition>
      </CommandUIDefinitions>
      <CommandUIHandlers>
        <CommandUIHandler Command="{06000B27-86BB-4203-AF44-29F61FDA678D}" CommandAction="~site/_layouts/PrintListItem/PrintListItem.aspx?List={ListId}&amp;ID={ItemId}" />
      </CommandUIHandlers>
    </CommandUIExtension>
  </CustomAction>

Custom action to add a Ribbon button in the Display Form of a SharePoint Document Library:

<CustomAction Description="Prints a single List Item" Title="Print List Item" Id="{055c63b4-58d8-4b4a-a366-70f69257b491}" Location="CommandUI.Ribbon.DisplayForm" RegistrationId="101" RegistrationType="List" Sequence="1000" Rights="ViewListItems" xmlns="http://schemas.microsoft.com/sharepoint/">
    <UrlAction Url="~site/_layouts/PrintListItem/PrintListItem.aspx?List={ListId}&amp;ID={ItemId}" />
    <CommandUIExtension xmlns="http://schemas.microsoft.com/sharepoint/">
      <CommandUIDefinitions>
        <CommandUIDefinition Location="Ribbon.ListForm.Display.Manage.Controls._children">
          <Button Id="{C75857A4-C0BC-439A-813A-A1DCC885A14A}" Command="{06000B27-86BB-4203-AF44-29F61FDA678D}" Image32by32="~site/_layouts/Icon/PrintIcon.jpg" Image16by16="~site/_layouts/Icon/PrintIcon.jpg" Sequence="1000" LabelText="Print List Item" Description="Prints a Single List Item" TemplateAlias="o1" />
        </CommandUIDefinition>
      </CommandUIDefinitions>
      <CommandUIHandlers>
        <CommandUIHandler Command="{06000B27-86BB-4203-AF44-29F61FDA678D}" CommandAction="~site/_layouts/PrintListItem/PrintListItem.aspx?List={ListId}&amp;ID={ItemId}" />
      </CommandUIHandlers>
    </CommandUIExtension>
  </CustomAction>

Custom action to add an item in the Edit Control Block of a SharePoint List:

<CustomAction Id="PrintListItem.ItemToolbar"
  GroupId="PrintListItem"
  RegistrationType="List"
  RegistrationId="100"
  Location="EditControlBlock"
  Sequence="100"
  Title="Print List Item"
  ImageUrl ="/_layouts/Icon/PrintIcon.jpg">
  <UrlAction Url="~site/_layouts/PrintListItem/PrintListItem.aspx?List={ListId}&amp;ID={ItemId}"/>
</CustomAction>

Custom action to add an item in the Edit Control Block of a SharePoint Task List:

<CustomAction Id="PrintListItem.ItemToolbar" GroupId="PrintListItem" RegistrationType="List" RegistrationId="107" Location="EditControlBlock" Sequence="300" Rights="ViewListItems"
Title="Print List Item" ImageUrl ="/_layouts/Icon/PrintIcon.jpg"><UrlAction Url="~site/_layouts/PrintListItem/PrintListItem.aspx?List={ListId}&amp;ID={ItemId}"/></CustomAction>

Custom action to add an item in the Edit Control Block of a SharePoint Document Library:

<CustomAction Id="PrintListItem.ItemToolbar"
  GroupId="PrintListItem"
  RegistrationType="List"
  RegistrationId="101"
  Location="EditControlBlock"
  Sequence="300"
  Rights="ViewListItems"
  Title="Print List Item"
  ImageUrl ="/_layouts/Icon/PrintIcon.jpg">
    <UrlAction Url="~site/_layouts/PrintListItem/PrintListItem.aspx?List={ListId}&amp;ID={ItemId}"/>
    <!--<UrlAction Url="javascript:window.open('{SiteUrl}/_layouts/PrintListItem/PrintListItem.aspx?List={ListId}&amp;ID={ItemId}','PrintListItem','height=600,width=800,resizable=yes,scrollbars=1');"/>-->
  </CustomAction>

Custom action to add a Ribbon item in the SharePoint 2010 Standard Actions Menu of a SharePoint List:

<CustomAction   GroupId="ActionsMenu" Location="Microsoft.SharePoint.StandardMenu" Sequence="1000" Title="Print List Item" ImageUrl="/_layouts/Icon/PrintIcon.jpg" Description="Print list item" RegistrationType="List">
<UrlAction Url="~site/_layouts/PrintListItem/PrintListItem.aspx?List={ListId}&amp;ID={ItemId}" />
</CustomAction>

Will keep updating this post with more Custom Action elements in the future.

10 comments:

  1. Hi,
    I have tried to use this code but I have one problem.
    Once the PrintListItem.aspx loads and I try Page.Request.QueryString["ID"]; all I get is {ItemId}
    How did you do to get the real value?
    //Carl

    ReplyDelete
  2. Which custom ribbon action piece of code mentioned above have you tried?

    ReplyDelete
  3. Great , thats a great post , i learn and work lot of things from this post..
    thanks you so much Mr. Mehul.
    Keep posting..

    ReplyDelete
  4. Thanks, great post!

    Here you find another sample to add a custom action to a ribbon bar. The sample adds a "Export to PDF" button to export SharePoint list data into a PDF document using a templating system:
    http://www.parago.de/2011/04/how-to-export-sharepoint-task-list-data-to-pdf-using-a-templating-system/

    ReplyDelete
  5. How do we customized the ribbon of an Infopath diplay form Displayifs.aspx. It's easy enough with the SP default new edit display forms but not with a customized Infopath form. Any ideas?

    ReplyDelete
  6. What goes on PrintListItem.aspx page or How do we create this application page with print preview list item content.

    ReplyDelete
  7. How can I take Custom Action ID{}, Button ID{} and command name{}

    ReplyDelete
  8. List={ListId} not working

    ReplyDelete
  9. Dear MEHUIL
    I would like to create a button in Ribbon.List that will print attached files existing in my current folder,
    can you help me please

    ReplyDelete