Tuesday, July 14, 2009

Add a Button to the Ribbon

Scenario:
To add a button to the sharepoint 2010 ribbon interface, is pretty much the same as adding Custom Action in MOSS 2007.

Solution:
Here's the element manifest file for developing a feature for adding a button to the ribbon to the Library tab in the Actions group for a document library (Type=101).

Element Manifest for the Feature:

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<CustomAction Id="Ribbon.Library.Actions.AddAButton"
Location="ViewToolbar"
RegistrationId="101"
RegistrationType="List"
Title="Add a Ribbon Button">
<CommandUIExtension>
<CommandUIDefinitions>
<CommandUIDefinition
Location="Ribbon.Library.Actions.Controls._children">
<Button Id="Ribbon.Library.Actions.NewRibbonButton"
Command="NewRibbonButtonCommand"
Image16by16="/_layouts/images/FILMSTRP.GIF"
Image32by32="/_layouts/images/PPEOPLE.GIF"
LabelText="New Button"
TemplateAlias="o2" />
</CommandUIDefinition>
</CommandUIDefinitions>
<CommandUIHandlers>
<CommandUIHandler
Command="NewRibbonButtonCommand"
CommandScript="javascript:alert('This is a new button!');" />
</CommandUIHandlers>
</CommandUIExtension>
</CustomAction>
</Elements>

0 comments: