Thursday, November 05, 2009

SharePoint 2010 – Adding new buttons to the SharePoint 2010 ribbon

Update: I just found this excellent training video – Module 10: Creating Dialogs and Ribbon Controls for SharePoint 2010. Would have saved us some trouble if we saw it beforehand.

We had a blast today at the SharePoint Ignite training as Koen already blogged in– Howto: Add a button to the ribbon in SharePoint. Fortunately Wouter (the trainer at the Ignite training) provided excellent background info and put us on the right track to get a working button.

I’m not going to elaborate about the exact syntax for adding buttons to the Ribbon – since this might change from Tech Preview to Beta2 but would like to provide some additional background info about how the new Ribbon works in SharePoint 2010:

  • The ribbon is actually rendered by a http handler which you find at C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\commandui.ashx
  • This http handler picks up the C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\GLOBAL\XML\CMDUI.XML file up and merges it with the different features which define additional customactions.
  • The different portions of the ribbon are cached in your temporary internet files – so you will some files in there which look like this commandui.ashx?ver=881443720&id=Ribbon.DocLibListForm.Edit&lcid=1033&qt=ribbonvisibletabdeep. Especially the id is important to identify the relevant parts in CMDUI.xml to take a look at. If you are deploying new customactions it might be safe to delete your tempfiles…
  • The ribbon is divided in Tabs which contains Groups of controls. A Group is rendered using a GroupTemplate. A Group can contain a number of controls such as Buttons, ToggleButtons, etc … it is easiest to just take a look at CMDUI.xml
  • You will not be able to modify the Ribbon arbitrarily – some groups in the ribbon have fixed controls which you should not modify (and to which you will not be able to add additional controls)– other groups can be modified.  You can add controls to groups which are using a so called flexible layout – such as Ribbon.Templates.Flexible. It is also possible to add additional groups.
  • The logic for the Ribbon can be found in the Microsoft.Web.CommandUI dll within the GAC (notice that there is no SharePoint in the naming…it might be possible that we see this dll appearing in other platforms as well). It can be quite interesting to take a closer look at this assembly using Reflector.
  • You will probably also notice a Scaling section within CMDUI.xml for each tab – this defines how the tab will render when you resize your browser…

No comments: