17

Does anyone knows how to show a custom action in the ribbon for only one list? At this moment I've got multiple custom lists, but my button is added on all of them. I only want to show it on one particular list...

(I found a simular question, but there isn't a good solution for it)

3 Answers 3

19

You can associate your custom action to a specific list by using the RegistrationId property.

Example:

<CustomAction ControlAssembly="MagicalProject.Actions" 
                ControlClass="MagicalProject.Actions" 
                ControlSrc="/_layouts/MagicalSite/MagicalPage.aspx" 
                Description="This is my custom action which does magical stuff" 
                GroupId="MyMagicalActions" 
                Id="f5bcd75e-23b9-4623-9a82-41cc7ceb10a6" 
                RegistrationId="MyMagicalList" // Or whatever other identifier you have for your lists
                RegistrationType="List" 
                RequireSiteAdministrator="false" 
                Rights="AddListItems" 
                Sequence="1" 
                ShowInReadOnlyContentTypes="false" 
                ShowInSealedContentTypes="false" 
                Title="MyCustomAction">

UPDATE: It also applies for ContentTypes. So if you associate it with a contenttype, then all lists inheriting that specific contenttype will also get this custom action. In case you wanted to know how to put it on more than 1 list.

All it takes is changing RegistrationType from List to ContentType

10
  • 1
    I've used as RegistrationId the Id from the list and than it worked perfectly. Thanks! Jan 26, 2012 at 9:50
  • 3
    Wasn't the registration id used to specifiy a list ServerTemplate id? You can associate the custom action to a specific template (es: generic list, document libray, image library ecc), but I don't think you can use the registration id to specify a string name of a list.
    – SPArcheon
    Jan 26, 2012 at 9:58
  • @SPArchaeologist According to MSDN you can. I think you might be thinking about RegistrationType.
    – user2536
    Jan 26, 2012 at 10:02
  • @Dandroid. From my experience, the registration id is used to specify a list template id (you must also set the parameter RegistrationType to "List"). That way you can for associate your action with every list of a set template - be it Survey (102), GenericList (100), PictureLibrary (109) ecc ecc. I am not aware if you could also use a list name/url/other in place of the template id - I will test this when I get some time, for now this is a nice thing to know (that would open new way to implement things).
    – SPArcheon
    Jan 26, 2012 at 10:19
  • 1
    @JohnDoDo: One more thing. I'm not sure I fully understood your situation, but if you need to add your custom action to a specific Content Type you may try to change the registration type to ContentType and set the RegistrationID to the id of your CT.
    – SPArcheon
    Feb 3, 2012 at 8:06
6

I've made some research on the subject of RegistrationId and RegistrationType according to declarative Ribbon customization. All my findings can be found here:

RegistrationType & RegistrationId in SharePoint 2010 declarative Ribbon customizations

As a short summary: You can use all four registration types to target some content for Ribbon customization.

And concerning your question: There's no direct option to specify single list instance by means of registrationid. But there's a workaround; you can create an unique content type for your specific list and use RegistrationType = ContentType to target it.

Another way you can go is the programmatic Ribbon customization.

4

You can use EnabledScript parameter in CommandUIHandler, where you can put javascript code and check if specific page/list/view is loaded.

Example:

<CommandUIHandler 
  Command="Ribbon.ListItem.CustomGroup.Controls.BtnSayHello.Command"
  CommandAction="javascript:alert('Hello');"
  EnabledScript="javascript:
    function isEnable(){
      if(location.href.indexOf('AllItems.aspx') > 0){
        return true;
      }
      return false;
    }
    isEnable();"
/>
3
  • 1
    beautiful hack !
    – gdbdable
    Jul 22, 2015 at 8:59
  • downvoted: WRONG answer - it still be in all lists (in disabled state)
    – dbardakov
    Apr 19, 2016 at 20:31
  • Why in all lists? You can easily specify to which list you register the action (see other posts)(sorry, I didn't mention this). But you cannot assign action to specify view of list. So my post gives you solution how to specify on which view/page will be the action visible. Apr 26, 2016 at 6:46

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.