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:
- Create a new folder under Sharepoint 14 Hive Features folder and name it as OrderDetails.
- Create a new Feature.Xml file under OrderDetails folder and paste the following code in XML file.
="1.0"="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.
- Create a new Default.xml file under OrderDetails folder and paste the following code in the XML file:
="1.0"="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:
- Go to List Settings --> Advanced Settings --> Allow Management of Content Types to be selected as Yes.
- List Settings --> Content Type Section --> Click the Document Content Type --> Get the
ctype
value from the URL. Here in my case, ctype=0x01010045A5D7FD06EBEC4B925C89A76834F101
. - Update this
ctype
value in the above Default.XML file as RegistrationID
attribute.
- Install the above feature using the following Powershell command:
Install-SPFeature OrderDetails
- 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
.
- 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