7
votes

Edit: Updated with input from Omlin

I am attempting to add a custom button to the ribbon. I want the button associated with a custom list named “Products”. I am able to get the button to show for a built-in list, such as a Shared Documents, but not the custom products list.

Below are examples of my code working with an existing list and not working with the custom list. I’ve also attached links to the working and non-working code that create the custom list and the ribbon button. These solutions assume that you have a site created at http://intranet.contoso.com. You will probably need to change Site URL of the project to get the code to run.


Working with and built-in list (Shared Documents):

Elements XML:

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
       <CustomAction
              Id="CustomRibbonTab"
              Location="CommandUI.Ribbon.ListView"
              RegistrationId="101"
              RegistrationType="List"
              Title="My Custom UI"
              Sequence="5"
              >
              <CommandUIExtension>
                     <CommandUIDefinitions>
                           <CommandUIDefinition Location="Ribbon.Documents.New.Controls._children">
                                  <Button
                                         Id="Ribbon.Items.New.RibbonTest"
                                         Alt="Test Button"
                                         Sequence="5"
                                         Command="Test_Button"
                                         LabelText="Click me!"
                                         Image32by32="/_layouts/images/ribbon_blog_32.png"
                                         Image16by16="/_layouts/images/ribbon_blog_16.png"
                                         TemplateAlias="o1"
                                         />
                           </CommandUIDefinition>
                     </CommandUIDefinitions>
                     <CommandUIHandlers>
                           <CommandUIHandler Command="Test_Button"
                                                         CommandAction="javascript:alert('I am a test!');">

                           </CommandUIHandler>
                     </CommandUIHandlers>
              </CommandUIExtension>
       </CustomAction>
</Elements>

Working Example Working Example

Full Visual Studio Solution: http://employees.claritycon.com/pwalke/blogs/working.zip


Not Working

Elements XML: I changed 2 lines from the above code.
Line 28: Associate the button with the custom products list, ID 10001, specified in the list template of the zipped code below.

RegistrationId="10001"

Line 85: Tell SharePoint to place the item within the Items menu.

<CommandUIDefinition Location="Ribbon.ListItem.New.Controls._children">

Screenshot – I would have expected the custom ribbon button to be added to the left of New Item. Not Working

Full Visual Studio Solution: http://employees.claritycon.com/pwalke/blogs/notworking.zip

3
+1 Very clear and detailed explanation of the problem.Andrey Markeev

3 Answers

7
votes

Ribbon.Items.New.Controls._children

According to MSDN, simply there is no such Ribbon location :)

I don't have SharePoint here right now to test, but I feel you need use Ribbon.ListItem.New.Controls._children


Update: So far, I tested the button adding to Ribbon.ListItem.New.Controls._children. It works fine for me (I haven't use any registration type & registration id yet). Sample code I used is:

  <CustomAction
  Id="ChangeBrowseTabTitle"
  Location="CommandUI.Ribbon">
    <CommandUIExtension>
      <CommandUIDefinitions>
        <CommandUIDefinition
          Location="Ribbon.ListItem.New.Controls._children">
          <Button
            Id="Ribbon.ListItem.New.RibbonTest"
            Alt="Test Button"
            Sequence="5"
            Command="Test_Button"
            LabelText="Click me!"
            Image32by32="/_layouts/SharePointTestProject/avatar32.png"
            TemplateAlias="o1"
              />
        </CommandUIDefinition>
      </CommandUIDefinitions>
      <CommandUIHandlers>
        <CommandUIHandler Command="Test_Button" CommandAction="javascript:alert('I am a test!');" />
      </CommandUIHandlers>
    </CommandUIExtension>
  </CustomAction>

The result is:

alt text

So I will try to test the custom list binging now.


Update: I took your "notworking.zip" project, and tried the code. With no luck. But when I created blank new list definition (Solution -> right-click -> Add -> New Item -> List Definition from content type), assigned custom id to it (10012), and changed reference in ribbon, it started working:

alt text


Final result

So something was wrong with your list definition, actually. I don't have enough time to check all the xml, so simply I created new list with same columns as I described above, deleted your old one, and all is working now. You can download the final solution, using this link:

https://sites.google.com/site/omlinfiles/StackOverflow.RibbonCustomList.zip?attredirects=0&d=1

P.S. don't forget to change Site URL

2
votes

If you want to add a ribbon button to a custom list, wich had been created through Site Actions Menu interface without feature on vs2010, you can do it setting the attribute RegistrationId to 100 (generic list).

Example:

    <?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <CustomAction
    Id="ListFolderSecurityButton"
    RegistrationType="List"
    RegistrationId="100"
    Location="CommandUI.Ribbon">
    <CommandUIExtension>
      <CommandUIDefinitions>
        <CommandUIDefinition
         Location="Ribbon.ListItem.New.Controls._children">
          <Button
           Id="Ribbon.ListItem.New.Controls.ListFolderSecurity"
           Alt="Gestiona los permisos de acceso de lectores en el folder"
           Sequence="10"
           Image32by32="/_layouts/images/Permissions32.png"
           Command="ManageSecurityFolder"
           LabelText="Folder Permissions"
           TemplateAlias="o2"/>
        </CommandUIDefinition>
      </CommandUIDefinitions>
      <CommandUIHandlers>
        <CommandUIHandler
         Command="ManageSecurityFolder"
         CommandAction="/CustomPages/PMS_AdminSecurityFolder.aspx" />
      </CommandUIHandlers>
    </CommandUIExtension>
  </CustomAction>
  <!--<HideCustomAction Id="Ribbon.ListItem.New.Controls.ListFolderSecurityButton" Location="Ribbon.ListItem.New.Controls._children">
  </HideCustomAction>-->
</Elements>
0
votes

I was able to resolve this issue. Thanks to omlin for getting me part of the way there.

This was a 2-part issue.

1: As suggested by omlin, I changed

Ribbon.Items.New.Controls._children 

to

Ribbon.ListItem.New.Controls._children

2: I had to change the schema.xml's toolbar declarations from

<ToolBar />

to

<Toolbar Type="Regular"/>