Add Custom action to the New group on the Ribbon for Document Libraries in SharePoint 2010
The Server Ribbon in SharePoint 2010 can be extended using Custom Actions to include additional links and controls. Various attributes and child elements of the CustomAction element can be used to target specific components of the Ribbon to include new controls in existing tabs and groups.
The "New" group on the Ribbon for can be extended by setting sthe Location attribute of a custom action to "CommandUI.Ribbon", and including a CommandUIEntension element in the CustomAction element which contains the details and location of the new control. The RegistrationId property of the CustomAction element is be used to target specific content types and list types such as a Document library. The RegistrationId for a Document library is 101 in all versions of SharePoint.
The CommandUIDefinition element contains the details of the control to be added to the New group on the Ribbon. The value should be set to "Ribbon.Documents.New.Controls._children". The "Ribbon.Documents.New.Controls" component of the location value indicates which component of the Ribbon to work with which is the Controls included in the existing New Group for Document Libraries. The "_children" component indicates that we are including our new Control as an additional child element of the "Controls" element.
The Child elements included in the CommanUIDefinition element can be controls such as a Button, Label, CheckBox, DropDown and many others. These elements will be added to the New Group when the Location property of the CommandUIDefinition element includes the value described above.
The TemplateAlias property of a control indicates which template to use when rendering the control. Most of the default templates and layouts used in the Ribbon have two Alias's, "o1" will generally render as a large control (32x32), and "o2" as a smaller control (16x16). there are different templates used in many cases, but most of the tab groups built into the Ribbon use the Flexible2 template (Ribbon.Templates.Flexible2), which renders controls with the template alias's as described above.
<CustomAction
Id="Ribbon.Documents.New.Controls.CustomLink"
Location="CommandUI.Ribbon"
RegistrationId="101"
RegistrationType="List"
Title="Add to Existing New Group on the Ribbon">
<CommandUIExtension>
<CommandUIDefinitions>
<CommandUIDefinition
Location="Ribbon.Documents.New.Controls._children">
<Button
Id="Ribbon.Documents.New.CustomLink"
Sequence="95"
Command="Documents.New.OpenCustomLink"
Image16by16="/_layouts/$Resources:core,Language;/images/formatmap16x16.png"
Image16by16Top="-32" Image16by16Left="-88"
Image32by32="/_layouts/$Resources:core,Language;/images/formatmap32x32.png"
Image32by32Top="-160" Image32by32Left="-448"
LabelText="New Group : Custom Link"
Description="Open Custom Link"
ToolTipTitle="Custom Action in New Group"
ToolTipDescription="Opens a Custom Link via a control added to the existing New group on the Ribbon under the Documents tab"
TemplateAlias="o1" />
</CommandUIDefinition>
</CommandUIDefinitions>
<CommandUIHandlers>
<CommandUIHandler
Command="Documents.New.OpenCustomLink"
CommandAction="http://www.master-sharepoint.com/"
/>
</CommandUIHandlers>
</CommandUIExtension>
</CustomAction>
The example above adds a new button to the New Group on the Ribbon for Document Libraries, which was taken from a tutorial referenced below. Details of the above sample CustomAction which adds a new control to the New group on the Ribbon for Document Libraries:
The location attribute of the CustomAction element is set to "CommandUI.Ribbon" (required for Riboon Customisations)
The RegistrationType attribute is set to "List" and the RegistrationId set to "101" to apply the Custom Action to the Ribbon for Document Libraries.
A CommandUIExtension element has a CommandUIDefinition element that contains the details of the new control for the Ribbon.
The Location attribute of the CommandUIDefinition element is set to "Ribbon.Documents.New.Controls._children", which is the location of the "New" group on the Ribbon for Document Libraries.
The CommandUIDefinition element has one child element "Button" which includes a button that opens a link when pressed.
The LabelText attribute of the Button element is set to the text that is displayed on the button (New Group : Custom Link).
The ToolTipTitle and ToolTipDescription contains the text that is displayed when the mouse is hovered over the button.
The TemplateAlias is set to "o1", which in this case will render a large button (32x32)
The Image32by32 attribute contains the url of the image to use on the button, which in this case is the same image used by many of the built-in controls on the Ribbon.
The Image32by32Top and Image32by32Left attributes indicate the position of the image to use.
The Command attribute of the button includes the command to execute when the button is pressed
The CommandUIHandler element also contains a "Command" attribute with a value that corresponds to the Command of the Button.
The CommandAction attribute of the CommandUIHandler element contains the URL that is opened when the button is pressed. In this case it opens an external internet site.
References:
SharePoint 2010: Extend the Document Library Menus, Ribbon and Settings Interface
This article provides a number of examples for customising the interface for Document Libraries, including adding new controls to the existing "New" Group on the Ribbon.
CommanUIDefinition Element Documentation
Defines an extension to the user interface, such as a button on a toolbar or a link on a site settings page.
CustomAction Documentation
Contains elements that define a user interface.
Submit a review:
Login required.