Tuesday, July 14, 2009

Adding and Removing a button to the Ribbon ( SharePoint 2010 )

*** Please view the disclaimer before you proceed ***

Scenario: Adding and Removing a button on the Ribbon. You can define the location on the Ribbon where you want the button to appear. Follow the below method to add a new button / remove the button to the Library tab in the Actions group for a document library.

How-To:

    1. Create a folder under 14 hive\Template\Features (SharePoint 2010 will have 14 hive similar to that of 12 in WSS / MOSS 2007) RibbonButton
    2. As seen in the previous post create the feature.xml
    3. Create a blank xml file, manifest.xml and add the below content (Adding Button) to it and Save it.
    4. Deploy the customization using Windows PowerShell as shown in my previous blog.
    5. Test it by navigating to the document library in your site / sub site and clicking on the library tab > Actions group > New Button button.
    6. To remove the button replace the content in the manifest.xml with the Removing Button content mentioned below.

Adding Button:



<?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>

// Image16by16 and Image32by32 are part of SharePoint 2010

Removing Button:



<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<HideCustomAction Id="RemoveRibbonButton"
Location="CommandUI.Ribbon.Library.Actions.ConnectToClient">
</HideCustomAction>
</Elements>

Technorati Tags: ,

No comments: