Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / productivity / SharePoint / SharePoint2010

Adding Custom Context Menu Item to a Specific SharePoint List

4.89/5 (3 votes)
10 Dec 2013CPOL2 min read 22.7K   78  
Adding Custom Context Menu to a Sharepoint List Using Features

Introduction

If you have ever tried adding a SharePoint custom action to the Lists actions menu and tried to specify a specific list or content type in the "RegistrationId", it doesn't work. SharePoint will silently not render your custom action. If you try and target a specific list using a "RegistrationId" of "100", you will see that SharePoint will render your action on each list of the site. Here is the solution for the same.

Using the Code

Follow the below steps to achieve the desired output:

  1. Create a new folder under Sharepoint 14 Hive Features folder and name it as OrderDetails.
  2. Create a new Feature.Xml file under OrderDetails folder and paste the following code in XML file.
    XML
    <?xml version="1.0" encoding="utf-8" ?>
    <Feature
    xmlns="http://schemas.microsoft.com/sharepoint/"
    Id="{AAD5B340-D5FC-4044-AA85-47528F137192}"
    Description="This feature contains a custom action that launches the Edit Order Details Page"
    Hidden="False"
    Title="Edit Order"
    Scope="Web"
    Version="1.0.0.0">
    <ElementManifests>
    <ElementManifest Location="Default.xml"/>
    </ElementManifests>
    </Feature>

    Make sure to generate a new GUID and update the above ID with your new GUID.

  3. Create a new Default.xml file under OrderDetails folder and paste the following code in the XML file:
    XML
    <?xml version="1.0" encoding="utf-8" ?>
    <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
    <CustomAction
    Id="ComprehensiveModifyItem"
    Location="EditControlBlock"
    Title="Edit Order"
    RegistrationType="ContentType"
    RegistrationId="0x01003A034A8880077243A36E17993E95DCB7">
    <UrlAction Url="~site/Lists/Shared%20Documents/EditOrderDetails.aspx?ID={ItemId}" />
    </CustomAction>
    </Elements>

    Make sure to replace the EditOrderDetails.aspx with your custom page. Here, the Registration ID is the List content type ID. To get the List content type ID, follow the below steps:

    1. Go to List Settings --> Advanced Settings --> Allow Management of Content Types to be selected as Yes.
    2. List Settings --> Content Type Section --> Click the Document Content Type --> Get the ctype value from the URL. Here in my case, ctype=0x01010045A5D7FD06EBEC4B925C89A76834F101.
    3. Update this ctype value in the above Default.XML file as RegistrationID attribute.
  4. Install the above feature using the following Powershell command:
    Install-SPFeature OrderDetails
  5. Enable the feature using the following Powershell command. We can also enable the feature using stsadm command.
    Enable-SPFeature OrderDetails -Url "http://SharepointPortal/CustomerOrders"

    Here CustomerOrder is the Subsite.

  6. The above feature will be enabled only to the Sharepoint List Shared Documents specified in the Registration ID.

Once you finish all the above steps, you will see a new menu item Edit Order for each list item in the Shared Documents List. If you notice other lists, you won't see this context menu item.

To disable and un-install the feature, use the below commands. Use -force option to force Install.

Disable-SPFeature OrderDetails -Url "http://SharepointPortal/CustomerOrders"

UnInstall-SPFeature OrderDetails 

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)