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
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.
Full Visual Studio Solution: http://employees.claritycon.com/pwalke/blogs/notworking.zip