Add to SharePoint 2010 Context Menu

Within SharePoint 2010, there is a ‘context menu’ that is shown when you click on a specific file – eg. DOCX.

image

This is actually known as the “Edit Control Block” or ECB.   Yep – another acronym for the kitbag.

To add functionality to the SharePoint 2010 ECB, we have to create a new SharePoint feature, with some XML within an ELEMENTS.XML file.

Here’s the steps to follow :

  • Open Visual Studio 2010
  • Click on “Empty SharePoint Project”
  • Name the project : NewContextMenuButton
  • Choose to ‘deploy as a farm solution’ when prompted

Within the new project, we need to add a new ‘elements’ file – and subsequent feature, etc.

  • Right-click on the project, and choose Add > New Item
  • Choose ‘Empty Element’
  • Enter the name as : NewContextMenuButton
  • Click CTRL+A (select all) and then Delete.
  • Paste in the following XML

<Elements xmlns=”http://schemas.microsoft.com/sharepoint/”>
  <CustomAction Id=”SPR.CustomButton”
                RegistrationType=”FileType”
                RegistrationId=”docx”
                Location=”EditControlBlock”
                ImageUrl=”/_layouts/IMAGES/DOCLINK.GIF”
                Sequence=”600″
                Title=”Custom Button”
                Description=”Click this button to see something magical occur…” >
    <UrlAction Url=”javascript: alert(‘Hello World !’)” />
  </CustomAction>
</Elements>

You can now simply right-click – and choose DEPLOY – that’s it…!     The feature & package name will be the default values – but they can be changed if needed.

Also – the IMAGE being used was just something that I found in the ‘layouts’ area of SharePointRoot.

Here’s the new Context Menu item – sorry, new addition to the Edit Control Block :

image

This will create a new entry for “DOCX” files – based on the “RegistrationType”.

You can also register for a specific Content Type, or ProgId – more information is available :

Next : How to call code – ie. do something useful !

UPDATE : Great post from Matt Thornton – who has extended this example beyond the ‘Hello World’ – with some Custom Code (C#)

Advertisements

2 thoughts on “Add to SharePoint 2010 Context Menu

  1. Pingback: SharePoint 2010 context menu item with custom code « Thornton Technical

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s