In this article, I will demonstrate How to Create a Custom Action for only one List via Visual Studio 2013 in SharePoint 2013.
I need to add a new Tab to Display Form Ribbon for only one list in SharePoint 2013 to be like this :
- Open Visual Studio > Create a new empty SharePoint solution .
- Select Deploy as a farm solution .
- Right Click on Project Name. > select Add.
- Add New Item.
- Add Module item.
- Delete Sample.txt file.
- Remove the current code at Element.xml.
- Paste the following code at Element.xml.
<?xml version="1.0" encoding="utf-8"?>
Description="Custom Tab !!!"
<Section Alignment="Top" Type="OneRow">
<ControlRef DisplayMode="Large" TemplateAlias="cust1" />
The important section of the above code is
- The location is the location that you want to add your custom action button / Tab within it. see also the full Location ID List.
- RegistrationId is the template type id of the object like the list , library … etc that you need to add a custom action within its ribbon. (or the Content Type ID for specific list).
- RegistrationType to define the type as List or Content Type or File Type or ProgID.
If you need to apply the custom action for all custom lists in DisplayForm so it should look like the following.
In my case, I only need to create a custom action for only one list in DisplayForm so
- Location = “CommandUI.Ribbon.DisplayForm“
- RegistrationId = “Content Type ID“
- RegistrationType = “ContentType“
So I should first create a site content type for this list by following the mentioned steps below:
- Go to List Settings. (Make sure that the content types has been allowed).
- Advanced Settings > Allow management of content types.
- Go to Site Settings > Web Designer Galleries > Site Content Type.
- Click Create.
- Set the name of the content type and set the other entries as the following:
- Go to List settings > below content types > click on Add from existing site content types
- Add the content type that you created
- Set it as default by clicking on Change new button order and default content type
- Check it and uncheck the default item content type > and select its order to 1.
- It’s should look like
- Now you should get Content Type ID by following the mentioned steps at Getting Content Type ID of SharePoint List.
- The final settings for location and registration id and registration type should look like the following
- Deploy the solution > go to your list > add new Item > display it > it should look like the following :
Please don’t hesitate to ask for more clarifications or request the source code at comments.