views:

138

answers:

2

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/"&gt;
       <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

+1  A: 

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&amp;d=1

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

omlin
Thank you very much for taking the time to read my issue and the the quick reply. I updated the code with those changes, but the ribbon button still does not show up on the custom list. I've looked at the ribbon xml definition in the 14 hive along with trying to debug the issue with firebug, but still no dice. Any further input is much much appreciated.
Peter Walke
Have you cleared the browser cache? (In IE - F12, menu Cache -> Always update from server). Anyway, I'll try to test the issue tomorrow morning (GMT+3) on my SharePoint environment.
omlin
Thanks for the input. I'll try this later today and let you know the results.
Peter Walke
A: 

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"/>
Peter Walke