2

How to add a ribbon item using CustomAction in sharepoint 2010

Anish
  • 75
  • 2
  • 2
  • 13

2 Answers2

3

I really recommend this blog-series: http://www.sharepointnutsandbolts.com/2010/01/customizing-ribbon-part-1-creating-tabs.html

Rikard Uppström
  • 1,413
  • 9
  • 16
3

Following are the steps to add a ribbon item(Button) called "Test Action 1" to a list with TemplateType = 10003 using CustomAction in SharePoint 2010

1.Add a new Element and add following code. Note that there are two CustomActions. One to add the Ribbon Button and the other to add the javascript file.

The RegistrationId is the same as the ListTemplateType.

For a list of Default Server Ribbon Customization Locations see this article.

   <?xml version="1.0" encoding="utf-8"?>
    <Elements xmlns="http://schemas.microsoft.com/sharepoint/"> 
      <CustomAction ShowInLists="TRUE" Id="TestAction1" RegistrationType="List" RegistrationId="10003" Location="CommandUI.Ribbon">
        <CommandUIExtension>
          <CommandUIDefinitions>
            <CommandUIDefinition  Location="Ribbon.ListItem.Actions.Controls._children">
              <Button  Id="Ribbon.ListItem.Actions.TestAction1" Alt="Test Action 1" Sequence="10" Image32by32="/_layouts/images/ACTIONSEDITPAGE.PNG" Command="Test_Action1" LabelText="Test Action 1" TemplateAlias="o2"/>
            </CommandUIDefinition>
          </CommandUIDefinitions>
          <CommandUIHandlers>
            <CommandUIHandler Command="Test_Action1" CommandAction="javascript:TestAction1();" />
          </CommandUIHandlers>
        </CommandUIExtension>
      </CustomAction>
      <CustomAction Id="Test.Ribbon.TestScript" Location="ScriptLink" ScriptSrc="~/_layouts/SPTest/TestJScript1.js" />
    </Elements>

2.Map the Layouts folder and add the TestJScript1.js file.

function TestAction1() {
    alert("This the test action 1");
} 

See the sample project structure

Sample Solution Explorer view