Building more complex SharePoint 2010 ribbon structure
This post assumes you already know the basics of building simple ribbon structure. If not, check out this 7 min screencast or this article.
In this post we’ll replace the contents of Elements.XML defining our custom ribbon with something more complex. In essence we’ll create a custom Tab and Group containing only one button. The result will look somethinglike this and when pressed the button will open a bing.com in a new page:
Here is the contents of Elements.XML, the code is as descriptive as possible and below I will include couple of more explanations to make the code more straightforward:
<?xml version=”1.0″ encoding=”utf-8″?>
<Elements xmlns=”http://schemas.microsoft.com/sharepoint/“>
<CustomAction
Id=”MyProject.RibbonButton”
Location=”CommandUI.Ribbon.ListView”
RegistrationId=”101″
RegistrationType=”List”>
<CommandUIExtension>
<CommandUIDefinitions>
<CommandUIDefinition
Location=”Ribbon.Tabs._children”>
<Tab
Id=”MyProject.Ribbon.HelloTab”
Title=”Custom Tab Title”>
<Scaling
Id=”MyProject.Ribbon.HelloTab.Scaling”>
<MaxSize
Id=”MyProject.Ribbon.HelloTab.MaxSize”
GroupId=”MyProject.Ribbon.HelloTab.HelloGroup”
Size=”OneLargeButton”/>
<Scale
Id=”MyProject.Ribbon.HelloTab.Scaling.TabScaling”
GroupId=”MyProject.Ribbon.HelloTab.HelloGroup”
Size=”OneLargeButton” />
</Scaling>
<Groups Id=”MyProject.Ribbon.HelloTab.Groups”>
<Group
Id=”MyProject.Ribbon.HelloTab.HelloGroup”
Title=”Custom Group Title”
Template=”MyProject.Ribbon.Templates.HelloTemplate”>
<Controls Id=”MyProject.Ribbon.HelloTab.HelloGroup.Controls”>
<Button
Id=”MyProject.Ribbon.HelloTab.HelloGroup.HelloButton”
Command=”MyProject.Scripts.HelloCommand”
LabelText=”Button Text!”
TemplateAlias=”CutomHelloTemplate”/>
</Controls>
</Group>
</Groups>
</Tab>
</CommandUIDefinition>
<CommandUIDefinition Location=”Ribbon.Templates._children”>
<GroupTemplate Id=”MyProject.Ribbon.Templates.HelloTemplate”>
<Layout
Title=”OneLargeButton”
LayoutTitle=”OneLargeButton”>
<Section Alignment=”Top” Type=”OneRow”>
<Row>
<ControlRef DisplayMode=”Large” TemplateAlias=”CutomHelloTemplate” />
</Row>
</Section>
</Layout>
</GroupTemplate>
</CommandUIDefinition>
</CommandUIDefinitions>
<CommandUIHandlers>
<CommandUIHandler
Command=”MyProject.Scripts.HelloCommand”
CommandAction=”javascript:window.open(’http://www.bing.com’);” />
</CommandUIHandlers>
</CommandUIExtension>
</CustomAction>
</Elements>
1. All of the ID’s in the XML are up to you to name with “whatever” naming conventions are acceptable . Obviously not “&” and other special characters that will break the XML
2. Be consistent with your ID’s since GroupID for example may be used in XML to define it’s look and feel and if you have inconsistencies, you will end up with JavaScript error.
3. All Location values are strict and have to be part of the subset that SharePoint 2010 is expecting, otherwise your controls will not be placed into expected areas (more likely they will not be placed anywhere at all).
4. In our example we attach the ribbon tab to a RegistrationType of a list – you can attach it to the content type as long as your RegistrationId and RegistrationType are defined accordingly.
5. <Tab> defines a tab.
6. <Scaling> defines how your control will render depending if the page is resized. In our example we use the same size. This definition is optional.
7. <Groups> defines groups under the <Tab>
8. <Group> defines individual group under <Groups>
9. Template attribute inside your <Group> will define how your group is layed out. The definition is in <GroupTemplate>.
10. <Controls> will contain your controls , in our case we just use <Button>
11. Command inside your <Button> will carry the name of the command that will execute when the button is clicked. This is later defined in <CommandUIHandler>
12. TemplateAlias contains the name of the template according to which your button will be layed out. Defined in <GroupTemplate><ControlRef>.
As you will see from the example in the earlier article which I referred to, your script doesn’t have to be all on one line, you can define it in a block as a separate CustomAction.
That is it, Enjoy!

Hi Yaroslav – great article. For me the new tab appears with the option button but unfortunately the original tabs then break if I click them as they intermittently display the content of the new tab unless I refresh the page. Does this happen for you?
Hi Ben,
I think I understand the problem you`re having .. no that doesn`t happen for me. The easiest way to check whether you`re using the proper syntax is to see how MS did it … Here is where you will find the file that defines pretty much everything on the SharePoint ribbon: C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\GLOBAL\XML\CMDUI.XML
@Yaroslav Pentsarskyy
Yaroslav,
I’m having the same difficulties as Ben, and also I can’t seem to figure out how to add a tab at the site level so that the user will see my new tab when they visit a team site rather than a list. Do you happen to know how that can be done?
Hey there Dasha, let me see if I have a chance to create a sample for this today.
@Yaroslav Pentsarskyy
Hey Yaroslav
Any success in creating a new Ribbon Tab at site level? I tried everything but i can’t get it to work!
Hi Yaroslav,
First of all, thanks for posting this, I was easily able to add a new custom tab to the document library list type, and it shows up with my custom groups/controls whenever I browse to a document library, and everything works beautifully.
However, I’m now running into the same problem as Dasha. That is, I can’t figure out how to take that custom tab and have it show up all the time (i.e., at the site level and not tied to a particular list type).
Here’s some of what I’ve tried so far (I’ll try to be brief),
I removed the RegistrationId & RegistrationType attributes from the CustomAction element and attempted to have a user control on the page execute code like the following:
protected void Page_Load(object sender, EventArgs e)
{
SPRibbon currentRibbon = SPRibbon.GetCurrent(this.Page);
if (currentRibbon != null)
{
currentRibbon.MakeTabAvailable(”Ribbon.MyTab”);
}
}
I added this user control to the “AdditionalPageHead” delegate control via a separate CustomAction element, and I was able to verify that this code is running via the Visual Studio debugger. The good news is that my custom tab shows up on the ribbon when I first load up the site in my browser, however, once I click on my custom tab, one of the following two things happens:
1) In IE my custom tab simply vanishes
2) In Firefox the ribbon does change the active tab, but then it just sits there displaying an Ajax loading icon within my custom tab rather than actually showing the button.
Of course, if I put the RegistrationId and RegistrationType attributes back in place (with the doc library-specific values) then everything works again, but not at the site level.
Any hints/help you could offer would be greatly appreciated.
Thanks,
Ash
Didn’t get a chance to take a detailed look at this yet … but if not today in very short few days.
Ahs, I’ll try to have a sample for you guys shortly. Seems like quite a few of you experience the same behavior.
Hey all,
It looks like there are finally some posts out there that shed some light on the situation:
http://www.projectserver2010blog.com/2010/01/sharepoint-2010-ribbon-customization.html
http://social.technet.microsoft.com/Forums/en/sharepoint2010customization/thread/d548d166-1afe-43c9-9562-0d6c1a771e1f
It looks like in order to have the custom tab show up on the page, one needs to add a web part that will enable it. Not as seemless as I was hoping..
Hi Yaroslav,
Thanks for the quick reply! I haven’t figured it out yet, but I did stumble across a bit of additional info from Elisabeth Olson @ MSFT within this forum entry:
http://social.technet.microsoft.com/Forums/en/sharepoint2010customization/thread/d548d166-1afe-43c9-9562-0d6c1a771e1f?prof=required&wa=wsignin1.0
Unfortunately, adding a CommandUIHandler and executing the SPRibbon.MakeTabAvailable method within the user control’s OnPreRender method didn’t do the trick for me (i.e., the user control that’s added to the default.master “AdditionalPageHead” delegate control).
Thanks again,
Ash
OK, so here is the solution.
First, create SharePoint project just like in this article that will have the following in Elements.xml (check this link: http://www.sharemuch.com/2010/01/20/creating-site-level-ribbon-tabs-in-sharepoint-2010-hiding-ribbon-on-demand/)
Basically a tab definition on a main Ribbon. NEXT, you have to create either a delegate control or a user control in your masterpage that will be called every the time the page loads and execute the following: Microsoft.SharePoint.WebControls.SPRibbon.GetCurrent(this.Page).MakeTabAvailable(”MyProject.Ribbon.HelloTab”);
You can use this to verify if the tab was already enabled:
Microsoft.SharePoint.WebControls.SPRibbon.GetCurrent(this.Page).IsTabAvailable(”MyProject.Ribbon.HelloTab”)
Hope that helps!
Hi Dasha, check reply to Ahs for my solution. Basically the only time your tab would not be visible if it was not defined properly in XML