Question

I have a problem with custom lists (of document library type) deployed from Visual Studio 2012 to SharePoint 2013. My custom action does not show up for such lists. Here is my custom action

SPUserCustomAction action1 = web.UserCustomActions.Add();
action1.RegistrationType = SPUserCustomActionRegistrationType.List;
action1.ImageUrl = "~sitecollection/myresources/Images/Logo16x16.png";
action1.RegistrationId = "101";
action1.Location = "EditControlBlock";                            
action1.Sequence = 500;
action1.Title = "Redirect to my page";
action1.Url = "javascript:__doPostBack('RedirectPostBack','{ItemId}|{ListId}');";
action1.Update();

This code works well for existing document libraries, I can see new context menu item for existing lists and new custom lists created from SharePoint web pages.

enter image description here

The problem is when I try to create and deploy new document library from Visual Studio. Custom action is not visible in context menu for such document libraries. I use default settings. This is my custom document library created in Visual Studio 2012

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
    <!-- Do not change the value of the Name attribute below. If it does not match the folder name of the List project item, an error will occur when the project is run. -->
    <ListTemplate
        Name="Space Check"
        Type="10000"
        BaseType="1"
        OnQuickLaunch="TRUE"
        SecurityBits="11"
        Sequence="110"
        DisplayName="Space Check"
        Description="My List Definition"
        Image="/_layouts/15/images/itdl.png"
        DocumentTemplate="121"/>
</Elements>

Any ideas? Thanks.

Was it helpful?

Solution

In order for custom action to appear in your custom list definition you need to change RegistrationId property to the value of Type property of your list definition. In your case it should be RegistrationId=10000

If you want to attach your custom action to all document libraries you can try to attach it to Document content type:

SPUserCustomAction action1 = web.UserCustomActions.Add();
action1.RegistrationType = SPUserCustomActionRegistrationType.ContentType;
action1.ImageUrl = "~sitecollection/myresources/Images/Logo16x16.png";
action1.RegistrationId = "0x0101";
action1.Location = "EditControlBlock";                            
action1.Sequence = 500;
action1.Title = "Redirect to my page";
action1.Url = "javascript:__doPostBack('RedirectPostBack','{ItemId}|{ListId}');";
action1.Update();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top