Creating site level ribbon tabs in SharePoint 2010, hiding ribbon on demand

fix

January 20th, 2010

In this article I will assume you already read and understand how to provision ribbon on the page, if not – check this article.

Here we’ll focus on what you need to do to create a new ribbon tab on the site level, which seems to be a hot topic these days. You need to perform two things

1. In your SharePoint 2010 project, add a new Empty Element item define the following XML:

<?xml version=”1.0″ encoding=”utf-8″?>

<Elements xmlns=”http://schemas.microsoft.com/sharepoint/”>
<CustomAction
Id=”MyProject.RibbonButton”
Location=”CommandUI.Ribbon”>
<CommandUIExtension>
<CommandUIDefinitions>
<CommandUIDefinition
Location=”Ribbon.Tabs._children”>
<Tab
Id=”MyProject.Ribbon.HelloTab”
Title=”Custom Tab Title”>
<Scaling Id=”Ribbon.Read.Scaling”>
</Scaling>
<Groups Id=”Ribbon.Read.Groups”>
</Groups>
</Tab>
</CommandUIDefinition>
</CommandUIDefinitions>
</CommandUIExtension>
</CustomAction>
</Elements>

Feel free to add any controls to your group as you need it.

2. Second one is to enable this tab on each page you of your site. This step is something very specific to site-wide ribbon tabs and to achieve the goal you can aither create a user control that will sit in your masterpage (header or footer) or delegate control and will be called on each page. The code that you will run in this user control will be something like this:

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”);

Keep in mind that this needs to run each time the page is loaded and the tab will show up along with all of the rest contextual tabs.

In some cases you would want to disable the whole ribbon in your page, how do you do that?

You need to follow #2 which is create a delegate control or a user control, but this time it will call the following code:

Microsoft.SharePoint.WebControls.SPRibbon.GetCurrent(this.Page).CommandUIVisible = false;

Hope that helps!


news

Any information posted on this blog does not reflect views of respective product vendors unless explicitely stated.

featured