Find the Id of a Ribbon button in SharePoint

When you are trying to customize the SharePoint Ribbon you might want to hide a few of the buttons. There are a few ways to do that, including obviously css manipulation. The recommended way is to deploy a custom action element with the following details.

<Elements xmlns="">
          Location="Ribbon.XXX.YYY.ZZZ" />

The text XXX.YYY.ZZZ symbolizes the name of the button on the ribbon. Most of the buttons have standard names, and can be guest, like the button for creating a new folder in a documents library – “Ribbon.Documents.New.NewFolder”. There are some buttons though, that are a bit different.

A good example is the button for editing with Infopath – “Ribbon.List.CustomizeList.Controls.btnCustomizeList2”. When looking for button names like this you may end up looking up the CMDUI.XML that is located in the SharePoint hive folder on the path: TEMPLATE\GLOBAL\XML. You can find a lot of the button names there, but unfortunately not all.

The solution to this problem is to look up the button id on the page. The id that we are looking for will be used there for the id of the link tag.

You could look up the button id in a few different ways, but probably the easiest would be to an elements inspector tool. Most modern browsers have this kind of tool automatically available in their developer tool suites.

With the inspector tool you can simply point to an element on the page, and see its properties. In the example below I am looking up the Infopath button.

Looking up the ribbon button id

Looking up the ribbon button id

Customizing the MySites masterpage in SharePoint 2010

I recently had the task of branding our SharePoint 2010. I just needed to change the main theme colors. I made a custom SharePoint 2010 theme (a good description of the SharePoint 2010 theming engine is here), and that did it for the main masterpage.

A problem came up thought with the MySites masterpage. It has an additional div area under the navigation pane.

MySites navigation area

MySites navigation area

Unfortunately theming this additional area is not supported in the SharePoint 2010 theme engine. I don’t really understand why. It is a basic theming matter, that should have been taken into account by the SharePoint team. But as with many others aspects of SharePoint, it is, what it is.

I finally resolved this by changing the style of the div section. To change it’s color for example you need to embed this code in the masterpage code.

<style type='text/css'> {
        background-color: rgb(174, 3, 3)

How to programmatically deploy SharePoint 2010 Web Templates

Web Templates have been available in SharePoint already since the 2007 edition. I find that they are a really helpful feature, and provide a much easier and quicker way to set up a provisioning mechanism for SharePoint sites.

This blog post however is not dedicated to explaining what Web Templates are about. There is already some great material out there. Here are two links, that you should start with, to understand the pros and cons of web templates:

Vesa’s Juvonen great post, that goes into great detail about Web Templates:

Miriam van Olst post about Site Definitions vs. Web Templates

A tutorial on how to save a site as a Web Template, and what goes into it.

Ok, so you now decided, that you want to use a Web Template. It’s pretty straightforward and well documented how you can do it manually, but how to do it in code?

Step 1: Save the site as a web template(as explained in the article linked above), and download the created solution file.

Step 2: Upload the solution file to your solution library, and activate it.

SPSite currentSite = SPContext.Current.Site.Solutions;
string templateName = 'TestTemplate';
SPUserSolution userSolution = null;
SPFile solutionFile = null;
string templateFilePath = @'\Templates\TestTemplate.wsp'

// Gets the solutions gallery for this
SPDocumentLibrary solutions = (SPDocumentLibrary)site.GetCatalog(SPListTemplateType.SolutionCatalog);

// Check is a solution file with this name already exists. If it does, delete it.
if (!site.RootWeb.GetFile(templateName).Exists)
userSolution = (from SPUserSolution s in currentSite.Solutions
where s.Name == solutionName
select s).FirstOrDefault();

if (userSolution != null)

// Upload the solution file
solutionFile = solutions.RootFolder.Files.Add(templateName, File.ReadAllBytes(filePath), true);

// Activate the solution
if(solutionFile != null)
userSolution = site.Solutions.Add(solutionFile.Item.ID);

Step 3: Activate the site collection feature for the template.

Guid solutionGuid = userSolution.SolutionId;

SPFeatureDefinitionCollection siteFeatures = site.FeatureDefinitions;

var featureDefinitions = from SPFeatureDefinition f
in siteFeatures
where f.SolutionId.Equals(solutionGuid) && f.Scope == SPFeatureScope.Site
select f;

foreach (SPFeatureDefinition featureDefinition in featureDefinitions)
if (GetFeature(site, featureDefinition.Id) == null)
site.Features.Add(featureDefinition.Id, false, SPFeatureDefinitionScope.Site);

Afther that your template will be available for you to use.

Happy coding.

PowerShell SharePoint snapin adding scriptlet

If you ever tried to run a SharePoint script, and did not do it from the “SharePoint 2010 Management Shell”, you know what I mean. You got something in the lines of:

“The term x is not recognized as a cmdlet, function, operable program, or script file, blah blah blah”

That’s because the “SharePoint 2010 Management Shell” besides running PowerShell also loads a snapin with SharePoint cmdlets. You have to do that too. Behold the code:

$snapin = Get-PSSnapin | Where-Object {$_.Name -eq ‘Microsoft.SharePoint.Powershell’}

if ($snapin -eq $null)
Write-Host “Loading SharePoint Powershell”
Add-PSSnapin “Microsoft.SharePoint.Powershell”

You just copy and paste this on the beginning of your PowerShell script, and voila. You can now say bye bye to the “SharePoint 2010 Management Shell” shortcut.