Friday, October 19, 2012

Custom SharePoint 2010 Ribbon Action for a Specific List Using Visual Studio 2010

Greeting to all my blog readers, we all know how good the sharepoint 2010 Ribbon is, and most wonderfull part is that it is Customizable by using both Visual Studio 2010 and SharePoint Designer 2010.

Recently on Microsoft Technet Forums a person asked this question: "I need a Ribbon Button for a Specific Lists using Visual Studio 2010" as he was thinking to attach Javascript code or CSOM code on that button(not possible with designer way), there was no way he was able to achieve the same using in Elements.xml file.

So i tried my luck with Server Side Object Model to achieve this and later even got the code Client Script object model and Server Side Object Model code to do this. In this blog i am only sharing the way i discovered this in server side object model.
I am showing code written as a Console Application to create a Ribbon Button on Specific List using Visual Studio.

It uses UserCustomActions Collection Property of SPList Object and to add a new UserCustomAction.
The Major Property is:
UserCustomAction.CommandUIExtension, this recieves token from the XML, the same way we enter in the Elements.xml during the traditional way. So here is how my code looks like:-  

 
 
 
 
 
Thats it and you will get a Explicit Ribbon button for a Particular List Only...