Search code examples
c#sharepointcustom-action

Add custom link to SharePoint list settings page by code


I would like to add a custom link to a SharePoint list settings page (listedit.aspx) from code, I have searched the web and Stack Overflow, and can't seem to find any examples or documentation on doing this specifically.

There are a dozen examples on how to do this from the elements.xml and on deployment/activation, but I would like to do this from C# code, like this:

SPUserCustomAction customAction = spCustomList.UserCustomActions.Add();
customAction.Url = "someurlhere";
customAction.Name = "CustomName";
customAction.Location = "Microsoft.SharePoint.ListSettings";
customAction.Title = "Custom Settings";
customAction.Update();
spCustomList.Update();

Solution

  • You are on the right track, but your Location is incorrect and you need a Group.

    Try the following:

    SPUserCustomAction customAction = spCustomList.UserCustomActions.Add();
    customAction.Url = "someurlhere";
    customAction.Name = "CustomName";
    customAction.Location = "Microsoft.SharePoint.ListEdit";
    customAction.Group = "GeneralSettings";
    customAction.Title = "Custom Settings";
    customAction.Update();
    

    For more information on Locations, see Default Custom Action Locations and IDs.