I needed to create a custom drop down action against documents in specific libraries in SharePoint 2010. Whilst this is possible to do easily using SharePoint Designer 2010, I thought it would be useful to make this reusable across a project.
The end result which I will demonstrate is as follows:
The following steps can be taken to achieve this. Note that I have kept this reasonably high-level.
Begin by navigating to a sample list/document library and editing the library in SharePoint Designer.
In the bottom right corner you can see a Custom Actions section.
Create a new custom action and specify the desired parameters. In my case I left this mostly to the defaults (display order etc) and decided in this example to simple navigate to an external URL.
Once you have created your action(s), close SharePoint designer and go back to the site which contains the library/list you applied the custom action to.
At this point you will see that the custom action is (hopefully!) visible and behaving as expected. The issue here is that what do you do when you want to reuse this custom action across a larger site or in my example – a specific content type. The following steps cover the packaging of this custom action. Note that I have assumed this is completely stand-along and does not need to be integrated with any other solutions for your project.
Now save the site as a template. This can be done via the UI or with the standard approach of: http://<sitename>/<subsite>/_layouts/savetmpl.aspx
Make sure you include content in the template.
Open Microsoft Visual Studio 2010 and create a new project. You will need to select the Import SharePoint Solution Package template.
Choose the desired deployment method – I have selected a sandboxed solution to speed things up.
At this point, you will need to select the project source – this is simply the site template that you exported above.
By default, all assets will be imported. You could do this and prune items later, but it’s much easier to just select the custom actions at this point. Note that a quick tip to deselect everything is to press Control + A and then tick the first item.
Scroll down until you see your custom action, then select this.
Within the Solution Explorer window you will be able to navigate to the Elements.xml file for your custom action.
When you open this you will see something similar to the below. We are interested in the RegistrationId and RegistrationType as these will need to be changed to make this reusable.
Change the RegistrationType to be “ContentType” and insert an ID for a content type (which I have assumed you have created earlier or will now tag out and create now) into the RegistrationId variable.
Once you have made your changes, save all and build/package/deploy the project.
If you go back to your site in SharePoint and navigate to Site Settings -> Solutions you should see your new solution in there if everything went well (SampleCustomAction) in my example.
If you now associate your content type with a library and create a new document (against that content type), then you should now see your custom action implemented.