Sometimes You need to add a new button to the list’s/library’s ribbon – nothing more simple than that. You jut need to create a new SharePoint project, add a feature, add an empty element with an Elements.xml file and define in it XML structure that will represent the new bottom.

Most of the time it will look similar to this:

Elements.xml:


<?xml version="1.0" encoding="utf-8"?>
 <Elements xmlns="http://schemas.microsoft.com/sharepoint/">

<CustomAction
 Id="{41C23DD2-6FEB-4636-AE4F-41B8E2A2D415}"
<strong> RegistrationId="100"</strong>
<strong> RegistrationType="List"</strong>
 Location="CommandUI.Ribbon"
 Sequence="5"
 Title="Custom Lists Button">

<CommandUIExtension>
 <CommandUIDefinitions>
 <CommandUIDefinition Location="Ribbon.List.Settings.Controls._children">
 <Button
 Id="{09A51440-C3A6-4103-874A-383747042E75}"
 Alt="Custom Lists Button"
 Sequence="5"
 Command="{42844423-382B-4e87-BEC4-34B0601DA98F}"
 Image32by32="/_layouts/images/menulistsettings.gif"
 Image16by16="/_layouts/images/itdcl.gif"
 LabelText="Custom Lists Button"
 TemplateAlias="o1" />
 </CommandUIDefinition>
 </CommandUIDefinitions>

<CommandUIHandlers>
 <CommandUIHandler
 Command="{42844423-382B-4e87-BEC4-34B0601DA98F}"
 EnabledScript=""
 CommandAction="javascript: alert('Custom Lists Button!');" />
 </CommandUIHandlers>

</CommandUIExtension>
 </CustomAction>
</Elements>

After deploying solution and activating feature the result is:

The disadventage of this approach is that this button will be shown on each existing Custom List. The reason for that is the RegistrationId=”100″. The 100 is the type of the Custom List. To bypass this and provide a button just for one instance of the list You can use one of the below ways:

1. Create a list definition and assing RegistrationId the list definition’s Type

First You need to create a new list defintion:

Open list defintion’s Elements.xml and copy Type value:

Paste the value to the RegistrationId of the button’s Elements.xml:


<CustomAction
Id="{67A1EB46-A49B-4aff-B456-068909C39599}"
RegistrationId="10000"
RegistrationType="List"
Location="CommandUI.Ribbon"
Sequence="5"
Title="List Definition Button">

<CommandUIExtension>
 <CommandUIDefinitions>
 <CommandUIDefinition Location="Ribbon.List.Settings.Controls._children">
 <Button
 Id="{3F083F8B-95D6-436b-A130-3EF1E8C04E3C}"
 Alt="List Definition Button"
 Sequence="5"
 Command="{AF90D558-00DA-4ccf-B4F4-169CD9162CD0}"
 Image32by32="/_layouts/images/menulistsettings.gif"
 Image16by16="/_layouts/images/itdcl.gif"
 LabelText="List Definition Button"
 TemplateAlias="o1" />
 </CommandUIDefinition>
 </CommandUIDefinitions>

<CommandUIHandlers>
 <CommandUIHandler
 Command="{AF90D558-00DA-4ccf-B4F4-169CD9162CD0}"
 EnabledScript=""
 CommandAction="javascript: alert('List Definition Button!');" />
 </CommandUIHandlers>

</CommandUIExtension>
 </CustomAction>

Finally, add the list definition to the feature, so it will be deployed along with the solution:

After activating the feature, You should be able to create a new list based on the  newly created list definition:

When You create a list from the definition You should be able to see the button:

Additionally, to prevent users from creating lists using the new list definition You can mark the definition as hidden(so users won’t see it) and You can create a list instance in the feature event receiver in the FeatureActivated method.

2. Add a button programmatically:

Add an event receiver to the feature:

Add below code to the FeatureActivated method:


public override void FeatureActivated(SPFeatureReceiverProperties properties)
 {
 //Depending from the feature scope - can be SPSite
 var web = properties.Feature.Parent as SPWeb;

//Get list instance - here You can also create a new list
 var list = web.Lists.TryGetList("RibbonButtonList");

if (list != null)
 {
 //Add new user custom action to the list
 var userAction = list.UserCustomActions.Add();
 //Set action's location
 userAction.Location = "CommandUI.Ribbon";
 //This one is Optional as we are adding the same later
 userAction.ImageUrl = "/_layouts/images/menulistsettings.gif";
 //Command body
 userAction.CommandUIExtension = @"<CommandUIExtension>
 <CommandUIDefinitions>
 <CommandUIDefinition Location=""Ribbon.List.Settings.Controls._children"">
 <Button
 Id=""{5557CC45-324E-41bb-9E88-A535DBF1BF6B}""
 Alt=""Programmatically Added Button""
 Sequence=""5""
 Command=""{234F6E9E-80A3-4f70-9683-02067515801E}""
 Image32by32=""/_layouts/images/menulistsettings.gif""
 Image16by16=""/_layouts/images/itdcl.gif""
 LabelText=""Programmatically Added Button""
 TemplateAlias=""o1"" />
 </CommandUIDefinition>
 </CommandUIDefinitions>

<CommandUIHandlers>
 <CommandUIHandler
 Command=""{234F6E9E-80A3-4f70-9683-02067515801E}""
 EnabledScript=""""
 CommandAction=""javascript: alert('Programmatically Added Button!');"" />
 </CommandUIHandlers>

</CommandUIExtension>";

userAction.Update();
 }
 }

After deploying the solution make sure that the list, to which we want to add the button, already exists and activate feature. You should see a new button on the list’s ribbon:

And that’s all! You should now be able to add a ribbon button to one list using one of the above methods!