Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to add a ribbon button to a custom list

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

like image 378
Peter Walke Avatar asked Sep 15 '10 18:09

Peter Walke


People also ask

How do I add a ribbon button to a library list in SharePoint?

In the Navigation pane, click the List and Libraries link, and then click the list name to which the custom action is to be added. Click the Custom Action menu in the list settings section in the ribbon and then click menu Display Form Ribbon to add custom action.

How to edit SharePoint ribbon?

Select File > Options > Customize Ribbon. To add a new tab to the ribbon, select New Tab. To remove a tab, in the Customize the Ribbon list, select it. Then select Remove.

Why can'ti see ribbon in SharePoint?

To show the ribbon controls if they are not visible, you must click on the Settings icon that looks like a cogwheel at the top-right corner of the page, and then select the Show Ribbon command from the drop-down menu that opens, as shown in Figure 2.4.


2 Answers

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

like image 77
Andrey Markeev Avatar answered Oct 24 '22 08:10

Andrey Markeev


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>
like image 22
yusta Avatar answered Oct 24 '22 09:10

yusta