2011-01-05

Ribbon CustomAction On All Lists

For a new component I am building, I wanted to allow users to perform an action on all lists. I thought about putting it in list settings, but hey this is 2011, lets put it in the ribbon. As i knew nothing about the ribbon it was a good opportunity to study for certification.

First i had to get a basic understanding of how it all worked, these pages helped a lot. (but you have to be careful of pages relating to the beta)

http://www.sharepointnutsandbolts.com/2010/01/customizing-ribbon-part-1-creating-tabs.html
http://makarandrkulkarni.blogspot.com/2010/01/sharepoint-2010-ribbon-customization_09.html
http://msmvps.com/blogs/cobrien/archive/2010/01/25/adding-ribbon-items-into-existing-tabs-groups-ribbon-customization-part-2.aspx

Adding a few simple buttons, i found out that adding a global button was not very straight forward. For starters most of the examples bind to lists, but i wanted to bind to all lists. Easy enough to change the RegistrationType to ContentType, just like you do with workflows and then the RegistrationId would be 0x01, the root content type of everything.

I tried to apply what i had learnt from the examples, to this global button, but it ended up in a mess.
Why?
Take these two list types as examples:
100 (GenericList) has a ContextualGroup "List Tools" with Tab "Items" and "List"
but
101 (DocumentLibrary) has a ContextualGroup "Library Tools" with Tabs "Documents" and "Library"
Each list type has different and unique Location paths, so you need to have a CommandUIDefinition for each location. Sure, i could duplicate the CommandUIDefinition definitions, but eventually someone would add a new list definition, with a different ribbon, and my button would not display. And duplicating xml definitions bugs me. It must be pointed out though that some people would not want an extra tab cluttering up their ribbon.

Then it hit me, i didn't have to add this button to an existing tab, i could create my own and that way the Location would be the same, globally. First i tried to create it as a ContextualGroup. Why would i do that? Well it would be cool to have a ContextualGroup called say Custom and then developers could add their custom actions to it. Unfortunately i couldn't get it to work without code. ContextualGroups need to be showed from code, which kind of makes sense (because they are contextual). So i just ended up with a simple Tab instead.

I ended up with something like this

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<CustomAction
Id="{CC1A996C-A50C-430f-8666-70747F7C8D9D}"
Location="CommandUI.Ribbon"
RegistrationType="ContentType"
Rights="ManageLists"
RegistrationId="0x01">
<CommandUIExtension>
<CommandUIDefinitions>
<CommandUIDefinition Location="Ribbon.Tabs._children">
<Tab
Id="Ribbon.Extended"
Title="Extended"
Description="Extended Settings"
Sequence="600">
<Scaling
Id="Ribbon.Extended.Scaling">
<MaxSize
Id="Ribbon.Extended.Scaling.SPC3.MaxSize"
Sequence="10"
GroupId="Ribbon.Extended.SPC3"
Size="Large" />
<Scale
Id="Ribbon.Extended.Scaling.SPC3.Scale"
Sequence="20"
GroupId="Ribbon.Extended.SPC3"
Size="Large" />
</Scaling>
<Groups Id="Ribbon.Extended.Groups">
<Group
Id="Ribbon.Extended.SPC3"
Sequence="10"
Description="SPC3 Settings"
Title="SPC3"
Template="Ribbon.Templates.ExtendedLarge">
<Controls Id="Ribbon.Extended.SPC3.Controls">
<Button
Id="Ribbon.Extended.SPC3.ShowIn"
Sequence="10"
Command="Ribbon.Extended.SPC3.ShowIn"
Image16by16="/_layouts/Com.CodePlex.SPC3/showhide16x16.png"
Image32by32="/_layouts/Com.CodePlex.SPC3/showhide32x32.png"
LabelText="Show In"
ToolTipTitle="Show In"
ToolTipDescription="Opens Show In configuration"
TemplateAlias="button1"
Alt="Show In" />
</Controls>
</Group>
</Groups>
</Tab>
</CommandUIDefinition>
<CommandUIDefinition Location="Ribbon.Templates._children">
<GroupTemplate Id="Ribbon.Templates.ExtendedLarge">
<Layout Title="Large" LayoutTitle="Large">
<Section Alignment="Top" Type="OneRow">
<Row>
<ControlRef DisplayMode="Large" TemplateAlias="button1" />
</Row>
</Section>
</Layout>
</GroupTemplate>
</CommandUIDefinition>
</CommandUIDefinitions>
<CommandUIHandlers>
<CommandUIHandler
Command="Ribbon.Extended.SPC3.ShowIn"
CommandAction="~site/_layouts/Com.CodePlex.SPC3/ShowIn.aspx?List={ListId}"
/>
</CommandUIHandlers>
</CommandUIExtension>
</CustomAction>
</Elements>

5 comments:

Brad Saide said...

Hi - Looks like this is what I need to do as well. Just wondering where you add it? Does this sit in a Masterpage, page layout etc? Is it in the Head section or Body? How does it get incorporated into the site?

Thanks!

Bradley Festraets said...

This is awesome! Well needed!
Thanks!

Anonymous said...

WAB

Anonymous said...

Where did you put this Elements.xml? In the MasterPage?

Unknown said...

have a peek at these guysthis content Get More Infohe said great post to readtry this out