Advertisement

  • How to: Create a Custom Action Specific to a List

    The Task
    Create a CustomAction (with GroupId of "ActionsMenu") that is specific to a custom list.

    The Challenge
    The challenge here is that the custom list is yet to be created and so the RegistrationId property of the CustomAction cannot be determined at the time of installing the CustomAction.

    The Solution(s)
    There are problably several ways to addres this task; 2 of which are:

    Option 1: Specify ControlAssembly and ControlClass properties for the CustomAction and in the custom control class build the menu item for the CustomAction if the list is the right list. The down side to this approach is that (1) the CustomAction is actually published on all list instances but built only for the appropriate list, (2) there's no way of indicating an identifier for the list without hardcoding its name/url in the custom control class. The upside is that (1) you can easily modify the behaviour of the CustomAction by simply revising the custom control class.

    Option 2: Create and activate the custom list and CustonAction using 2 different features one after the other with the feature for the custom list going first. Then using Feature event receiver class for the feature of the custom list, update the element.xml file for the CustomAction's feature; prior to attempting to install and activate it; with the GUID of the list instance you just created. This approach with ensure that the CustomAction you just created is available only in the custom list you just created as well. The downside, however, is that any change to the CustomAction requires a reinstallation & reactivation of the feature.

7 comments:

  1. PING says:

    Hi,

    I have Written a Blog explaning "how to Create Custom Action For Specific To list"

    http://mnish.blogspot.com/2009/04/create-custom-action-specific-to-list.html

    Visit this Blog and Let me know if this works for you.

  1. Raphael Iloh says:

    Hi PING,
    Thanks for your comment on my blog post. I was not particularly looking for how to create a custom action specific to a list but was commenting on how to create one.

    My post was all about "How to Create a Custom Action Specific to a List". In other words, how to create a custom action that is not specific to any content types and is not associated with all lists; but a content type that is specific and associated with 1 and only 1 specific list.

    Nevertheless, I had the chance to review your post as par the url you provided. While the post is good and commendable, I'm afraid you won't describe it as How to "Create a Custom Action Specific to a List".

    You see the custom action you created is specific to a "Content Type". This means that the custom action will appear in all lists or document libraries where the content type is used. So, a more appropriate title will be "How to Create a Custom Action Specific to a Content Type".

    Furthermore, you rightly spotted the possible values for the RegistrationType attribute as ContentType, FileType, List, and ProgId. It may interest you to know that even setting the value of the attribute to "List" still won't achieve the expected outcome. What you'd get, rather, is custom action that applies to all lists and NOT specific to a list, if you see my point.

    I suppose your comment has brought up the need for me to put together some codes to drive the point farther home. Watch this space...

  1. Anonymous says:

    Can you please attach an exaple for the first solution you have proposed?

    Thanks

  1. Anonymous says:

    I think Ping's example works fine, I have used something like it before, each sharepoint list creates a new "contenttype" for each implemenation of it uses of other content types. You simply use the contenttypeid this is specific to the list (You dont use the contenttypeid of the document content type you use the contenttypeid of list "xyz"'s implementation of the document content type) He does explain this in the post

  1. sanketinfo says:

    Hi,

    Did you tried to add custom action into “NEW” toolbar item for specific list?

    I have one problem into CustomAction tag, if I use location as “Microsoft.SharePoint.StandardMenu” and GroupID as "NewMenu" then it didn’t work for me, I mean, I can’t see my custom link into “NEW” menu, if I didn’t use for specific list and remove RegistrationType and RegistrationID then it’s working fine and I can see new custom item into all lists, but I would like to display new custom menu into “NEW” item for specific list.

    Do you have any idea what I need to change or where I am missing?

    CustomAction
    Id = "CustNewLink"
    RegistrationType="ContentType" RegistrationId="0x0101006F0588113A5C1F439B176C99A35B41C5"
    Title = "Custom Create Title"
    Sequence="2000"
    Description = "description goes here."
    GroupId = "NewMenu"
    Location = "Microsoft.SharePoint.StandardMenu"

    Above code didn’t work.

    Thanks in advance,
    Sanket Shah

  1. Hollywood says:

    Hi All,

    if you have a list which is not based on a content type and you have several dependecies, e.g. to web services, so that you cant not change this, simply check the radio button of extended list settings and allow content types.
    add the contenttypeid of the liscontenttype element to the customaction tag RegistrationId and set Registrationtype="ContentType".
    This works great in my environment. (Just to that specific list!)

    Good luck
    Hollywood