SharePoint Pals
 | Sign In
How to Add Custom Ribbon Action on List/Libraries in SharePoint 2013
by Sathish Nadarajan 12 May 2014
Author
SharePoint MVP
Visits   
Today  :   19     Total  :    24048

In this article, let us see how to create a Custom Ribbon Action on the Libraries/List on SharePoint 2013. On click, we can see, how to call a Javascript method.

Before get in to the steps, let us see, how we want and what we are going to achieve on this article. The output is somewhat like,

image

Now, let us see by step by step.

1. Open the visual studio 2012 as run as administrator.

2. Create an Empty SharePoint Project.

3.image

4. Select a Farm Solution.

5.image

6. Add New Item to the solution.

7.image

8. Add a Module. Name it as CustomRibbonActionModule.

9. By default, it will have a sample.txt. Now delete that txt file, since we don’t require that.

10. And modify the Elements.xml as below.

 <?xml version="1.0" encoding="utf-8"?>
 <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
 
   <CustomAction
     Description="CustomActionDescription"
     Id="CustomActionID"
     Location="CommandUI.Ribbon">
     <CommandUIExtension>
       <CommandUIDefinitions>
         <CommandUIDefinition
           Location="Ribbon.Library.Groups._children">
           <Group
             Id="CustomActionGroupID"
             Sequence="80"
             Description="CustomActionGroupDescription"
             Title="CustomActionTitle"
             Template="Ribbon.Templates.Flexible2">
             <Controls Id="CustomActionControlsID">
               <Button
                 Id="CustomActionButtonID"
                 Command="CustomActionButtonCommand"
                Image32by32="_layouts/15/images/placeholder32x32.png"
                 LabelText="CustomActionButtonLabelText"
                 TemplateAlias="o2"
                 Sequence="10"/>
             </Controls>
           </Group>
         </CommandUIDefinition>
         <CommandUIDefinition
           Location="Ribbon.Library.Scaling._children">
           <MaxSize
             Id="CustomRibbonActionsOneMaxSize"
             Sequence="15"
             GroupId="CustomActionGroupID"
             Size="LargeLarge"/>
         </CommandUIDefinition>
       </CommandUIDefinitions>
       <CommandUIHandlers>
         <CommandUIHandler
           Command="CustomActionButtonCommand"
           CommandAction="javascript:alert('Test');"/>
       </CommandUIHandlers>
     </CommandUIExtension>
   </CustomAction>
 
 </Elements>
 

The above XML is self explanatory I guess. The most important things on the XML are

1. Location – “Ribbon.Library.Groups._children”.

2. TemplateAlias – “o2”.

To know more about the Locations, please refer to the MSDN articles

· http://msdn.microsoft.com/en-us/library/office/ee537543(v=office.15).aspx

· http://msdn.microsoft.com/en-us/library/office/bb802730(v=office.15).aspx

In the same above XML, if we want to call a Javascript method instead of an alert, the CommandUIHandlers will become like this.

 <CommandUIHandlers>
         <CommandUIHandler
           Command="CustomActionButtonCommand"
           CommandAction="javascript:SayHello(); 
 function SayHello() { 
 alert('Hello'); 
 }"/>
       </CommandUIHandlers>
     </CommandUIExtension>
 

In the next Article, let us see how to insert a piece of content on click of a ribbon button into your content area on a Publishing Site.

Happy Coding.

Sathish Nadarajan.

blog comments powered by Disqus

SharePoint Pals

Pals
SharePoint Pals, a community portal for SharePoint developers, Administrators and End Users. Let's join hands and share the point together.
Read this on mobile

Training

Angular Js Training In Chennai
Advanced Angular Js training with real world developer scenarios
Angular Js, Web Api and Ionic for .Net Developers
All in one client side application development for .Net developers
Angular Js For SharePoint Developers
Get ready for the future. Its no more just C#

Get Connected

SharePoint Resources

SharePoint 2013 and 2010 Web Parts
Free Web Parts with Source Code for SharePoint Community




SharePoint 2013 Books and Tutorials
Collection of free SharePoint 2013 books and tutorials (eBooks, pdfs)

Supported By

Contribute your article and be eligible for a one month Free Subscription for Plural Sight. The Author of the most popular New Article (published in the previous month) will be awarded with a Free One month Plural Sight Subscription. Article can be sent to articles@sharepointpals.com in a word document.

Related Resources

Recent Tweets

Twitter January 15, 00:25
How To Enable Target Value And Actual Value In #D3 Gauge Chart https://t.co/VxSi4QnNrC

Twitter January 15, 00:24
How To Open #SharePoint List Hyperlink Column In Modal #Popup Window https://t.co/EQ7HkoZDkX

Twitter January 15, 00:24
Quick Introduction To #Asp.NetCore And It’s Features https://t.co/zAXObHCFpH

Twitter January 15, 00:22
How To Configure #PerformancePoint Services To Use Secure Store In #SharePoint 2013 https://t.co/LEwnUoI7EY

Twitter January 15, 00:21
How To Block Or Disable #Office365 Services https://t.co/Yvp2VPFIRP

Follow us @SharePointPals
Note: For Customization and Configuration, CheckOutRecent Tweets Documentation