Monday, October 24, 2011

Adding Custom Context Menu Item to Edit Control Block in SharePoint 2010

Within SharePoint 2010, there is a ‘context menu’ that is shown when you click on a specific file – eg. DOCX.
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=””>
<CustomAction Id=”SPR.CustomButton”
Title=”Custom Button”
Description=”Click this button to see something magical occur…” >
<UrlAction Url=”javascript: alert(‘Hello World !’)” />
< /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 :
This will create a new entry for “DOCX” files – based on the “RegistrationType”.

No comments:

Post a Comment