Tuesday, September 22, 2009

Troubleshooting SharePoint 2010 Ribbon buttons

While I was preparing to my presentation on SharePoint 2010 in Las Vegas next month, I wanted to show how to add some new cool buttons to the new ribbon menu.

I came across a lot of bloggers writing about this new feature (ribbon),
here is a nice how-to published by Sandeep K Nahta back at July:

But what it does not say and took me a while to understand is few things that makes this not work according to plan...


Keep in mind your feature must be at a site collection level otherwise it will not work.
Farm level will not load anything and site level will work in strange resutls like:
Adding the buttons twice, or if you activate it on 2 sites in the same collection - adding the buttons permanently even after you deactivate the feature and uninstall it.


I wanted to name my actions SLFE.SomeAction (product code.actio name) for our SharePoint List Forms Extensions ( hence SLFE :) ), Now the buttons I added were disabled all the time. Took me a whilte to figure out that the action name must not containt special characters including ... so - keep that also in mind.


The easiest way I found for adding buttons or groups into the existing ribbon is:
- find the location you want to add it in the existing ribbon definition file (C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\GLOBAL\XML\CMDUI.XML)
- locate the XML node you wish to insert you XML addition, and keep it's ID value.
- simply inject your XML in your feature elements file to that node's children collection like so (note the CommandUI. and ._children in the custom action's location):
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <CustomAction Id="KWizCom.SLFE.Ribbon.Library.Groups.SLFE" Location="CommandUI.Ribbon.Library.Groups._children" Sequence="2000" Title="SLFE">
... XML as in the CUI schema ...


If you don't see any buttons when you add a group - you must add "scaling" properties for that group!

Also - make sure your chosen template (i.e. Ribbon.Templates.Flexible) support your control's TemplateAlias (i.e. o1). Don't you just hate these XML cross references?!

I will post back here with more info on the ribbon as I find it, check back to update!

Thanks, Shai.


Anonymous said...

Dont propose SharePoint community something, which is not best practice. You should not modify OOTB CMDUI.xml file, instead you should create your own xml file.

Shai Petel said...

Dear Anonymous,

Please read before you blame - I did not suggest to modify the OOB file, I just pointed to it in order to find the ID of the location we want to add buttons to.

Step C clearly states xml injections are to be made to the feature elements file.

I don't know what you misread or misunderstood, but the post is very clear about this, I think. If you can point me to where you got confused perhaps I could rephrase that part to be more clear.