1

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?

0

2 Answers 2

1

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/">
  <CustomAction 
    Id="ECBItemCustomization"
    RegistrationType="List"
    RegistrationId="101"
    Location="EditControlBlock"
    Sequence="106"
    Title="Navigate to Site Settings">
    <UrlAction Url="/_layouts/Settings.aspx"/>
  </CustomAction>
</Elements>

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

RegistrationId="101"

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

https://stackoverflow.com/questions/1999642/custom-action-menu-for-particular-sharepoint-list

6
  • what do you mean with template id?
    – Shkipper
    Feb 21, 2013 at 20:44
  • did you see the list I have provided you, each list type has a template id Feb 21, 2013 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, 2013 at 21:16
  • Is the list you want to add it to is a custom list ? Feb 21, 2013 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, 2013 at 22:00
0

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:

  <CustomAction
      Id="GoToGoogle"
      Title="Go To Google"
      Location="Microsoft.SharePoint.StandardMenu"
      RegistrationId="101"
      RegistrationType="List"
      GroupId="ActionsMenu"
      Sequence="1000"
      ControlAssembly="Assembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cd112ea8ee9f48d3"
      ControlClass="Assembly.CustomActions.MyCustomAction" >
    <UrlAction Url="http://www.google.com"/>
  </CustomAction>

Here is the class which you need:

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

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            if (!Page.IsPostBack)
            {
                EnsureChildControls();
                _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()
        {
            base.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"}"
            };
            Controls.Add(_MenuItemTemp);
        }

        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)

1
  • 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/… Feb 27, 2013 at 8:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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