7

I want my Custom Action Menu to be applied to particular list; currently its specified with the following XML and it gets applied to all the lists!

More specifically speaking; I even want this custom action to be applied to a particular view of the particular list...

<CustomAction
    Id="MyCustomActionId"
    Title="My Custom Action"
    Description="My Custom Action Description"
    RequireSiteAdministrator="FALSE"
    RegistrationType="List"
    GroupId="ActionsMenu"
    Sequence="1000"
    Location="Microsoft.SharePoint.StandardMenu" >
    <UrlAction Url="{SiteUrl}/_layouts/MySharepointArtifacts/MyCustomAction.aspx?ListId={ListId}"/>
  </CustomAction>

How can I do this?

Khurram Aziz
  • 1,480
  • 5
  • 15
  • 24
  • I already have stsadm extension in place to fix the lookup fields. It would be fine to add another extension. Can I access the Custom Action being configured through Sharepoint Object Model? – Khurram Aziz Jan 06 '10 at 08:27
  • I have also tried adding the link in the list' schema.xml (List / Views / ViewHeader) and its being accepted by the users. There I need to know the equivalent of UrlAction ~site moniker to give in – Khurram Aziz Jan 06 '10 at 08:34

2 Answers2

9

Creeate a content type (based on the item you want to create the ECB menu on) and add the content type to your list. Create a customAction and register it to the content type. The ECB menu will only show on items of the given content type in lists where you added the content type.

Here is a Content type base on the build in document content type:

    <?xml version="1.0" encoding="utf-8"?>
<Elements Id="f55bc095-86f5-4c0a-961e-0e8f8e6c50ed" xmlns="http://schemas.microsoft.com/sharepoint/">
  <ContentType ID="0x0101002936a05e70da4cf2a6846c669da7fdb6"
               Name="CTName"
               Group="CT group Name"
               Description="CT description"
               Version="0">
    <FieldRefs>...

Create a custom action to the content type (ref. content type id):

    <CustomAction
        Id="MyCustomActionId"
        Title="My Custom Action"
        Description="My Custom Action Description"
        RequireSiteAdministrator="FALSE"
        RegistrationType="ContentType"
RegistrationId="0x0101002936a05e70da4cf2a6846c669da7fdb6"
        GroupId="ActionsMenu"
        Sequence="1000"
        Location="EditControlBlock" >
        <UrlAction Url="{SiteUrl}/_layouts/MySharepointArtifacts/MyCustomAction.aspx?ListId={ListId}"/>
      </CustomAction>
Tomso
  • 326
  • 1
  • 4
  • 2
    I could be wrong, but for me, this code only worked with "Location="EditControlBlock". – brentlightsey Mar 11 '10 at 19:57
  • @lividsquirrel is correct -- locking a CustomAction down to a particular Content Type ID through the above method doesn't work when Location="Microsoft.SharePoint.StandardMenu" and GroupId="ActionsMenu", but it does work when Location="EditControlBlock" (again as @lividsquirrel states). – John Berberich May 06 '11 at 15:36
  • It's correct that you must use the Location="EditControlBlock" to make it work. I will update my answer. – Tomso May 09 '11 at 12:40
1

It is not easy to target customActions to specific lists. One very tiny description I've found is here: http://www.dotnetprodigy.com/2009/01/how-to-create-custom-action-specific-to.html (and another here: http://mnish.blogspot.com/2009/04/create-custom-action-specific-to-list.html)

naivists
  • 32,681
  • 5
  • 61
  • 85