I have a question regarding the custom action, basically I would like to create a custom action in ribbon for only ONE SharePoint list, this list already exist and i cannot and i dont want to modify it, but i need to add a custom action.

Is there a possibility only by knowing the list name / id etc ... bind to it a custom action?

I just want to emphasise that we are talking about sharpoint 2007.

If there is a way, could anyone tell me the best way to do it?


Each list type has list template for example 101 for Document library list. Now if you have a custom list with a template ID which is unique to this list then you can create a custom action feature and in xml tag of your custom action you can provide that unique list id other then that if its not custom list then am not sure if you can do it or not @2007.

List of list template ids

So if you want custom action for all document libraries you can try this,

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
    Title="Navigate to Site Settings">
    <UrlAction Url="/_layouts/Settings.aspx"/>

but as you said you want it just for a single list then if its a custom list you can get its id and put it in here


If above isn't the situation then you can create a content type and do what you want to do, here's the link


  • what do you mean with template id? – Shkipper Feb 21 '13 at 20:44
  • did you see the list I have provided you, each list type has a template id – Muhammad Raja Feb 21 '13 at 21:07
  • oh ok, but it is not what i want, i know how to add custom actions to all particular soort of list etc etc ... but i need to find a way how to add a custom action, just for one particular list. – Shkipper Feb 21 '13 at 21:16
  • Is the list you want to add it to is a custom list ? – Muhammad Raja Feb 21 '13 at 21:16
  • yes, it is custom list, but i have a lot of custom lists in site collection, and i only need this to this one, no matter what. – Shkipper Feb 21 '13 at 22:00

I will answer myself to this post, as I finally found the solution.

You have to create a custom action with controlclass, and in the control class you programmatically hide or show the custom action depending on the list name.

Here is the full code:

      Title="Go To Google"
      ControlAssembly="Assembly, Version=, Culture=neutral, PublicKeyToken=cd112ea8ee9f48d3"
      ControlClass="Assembly.CustomActions.MyCustomAction" >
    <UrlAction Url="http://www.google.com"/>

Here is the class which you need:

public class MyCustomAction : WebControl
        private MenuItemTemplate _MenuItemTemp;
        private string list;

        protected override void OnLoad(EventArgs e)
            if (!Page.IsPostBack)
                _MenuItemTemp.Visible = false;
                ListViewWebPart listView = GetParentListViewWebPart();
                if (listView != null)
                    list = SPContext.Current.List.ToString();
                    if (list == "Test")
                        if (SPContext.Current.Web.UserIsSiteAdmin)
                            _MenuItemTemp.Visible = true;

        protected override void CreateChildControls()
            SPWeb site = SPContext.Current.Web;
            Guid ListId = SPContext.Current.ListId;
            _MenuItemTemp = new MenuItemTemplate
                Text = "Go To Google",
                Description = "Go To Google",
                ImageUrl = "/_layouts/images/ActionsSettings.gif",
                ClientOnClickNavigateUrl = @"http://www.google.com"}"

        private ListViewWebPart GetParentListViewWebPart()
            Control parent = Parent;
            while (parent != null)
                if (parent is ListViewWebPart)
                    return (ListViewWebPart)parent;
                } parent = parent.Parent;
            } return null;

IMPORTANT: make sure to register this class as safe class else you will have an issue, with not displaying anything (no error also)

  • The link I have given you already explains you the way you just did it, DON'T EXPECT PEOPLE TO DO YOUR WORK, to be exact check "Option 1:" in link given below which is already provided in the question link I have given you, dotnetprodigy.com/2009/01/… – Muhammad Raja Feb 27 '13 at 8:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.