How do you create a Ribbon Button custom action that will appear on all kinds of lists
-
16-10-2019 - |
Question
I want to create a ribbon button that will work with all kinds of lists. I mean, the same custom action should work against lists, document libraries, Announcement lists, etc..
Also. It should work regardless of the content types contained in the list.
What should be the custom action definition for this?
Solution
Just hook it to the 0x01 Content Type.
An example of the syntax used in our SharePoint Audit suite is as follows:
<!-- Add a new action to the SharePoint 2010 Ribbon bar for each list to show all audit entries for a list Item -->
<CustomAction
Id="Muhimbi.SharePoint.Audit.Ribbon.ListItem.Share.ViewAuditLog.Action"
Location="CommandUI.Ribbon"
RegistrationType="ContentType"
RegistrationId="0x01"
>
<CommandUIExtension>
<CommandUIDefinitions>
<CommandUIDefinition
Location="Ribbon.Documents.Share.Controls._children">
<Button Id="Muhimbi.SharePoint.Audit.Ribbon.ListItem.Share.ViewAuditLog.Button"
Command="Muhimbi.SharePoint.Audit.Ribbon.ListItem.Share.ViewAuditLog.Button.Command"
Image16by16="/_layouts/images/Muhimbi.SharePointAudit/Report16.gif"
Image32by32="/_layouts/images/Muhimbi.SharePointAudit/Report.gif"
LabelText="$Resources:MuhimbiAuditProvisioningResources,ECB_ViewAuditLog;"
Sequence="11"
TemplateAlias="o1" />
</CommandUIDefinition>
<CommandUIDefinition
Location="Ribbon.ListItem.Share.Controls._children">
<Button Id="Muhimbi.SharePoint.Audit.Ribbon.ListItem.Share.ViewAuditLog.Button"
Command="Muhimbi.SharePoint.Audit.Ribbon.ListItem.Share.ViewAuditLog.Button.Command"
Image16by16="/_layouts/images/Muhimbi.SharePointAudit/Report16.gif"
Image32by32="/_layouts/images/Muhimbi.SharePointAudit/Report.gif"
LabelText="$Resources:MuhimbiAuditProvisioningResources,ECB_ViewAuditLog;"
Sequence="11"
TemplateAlias="o1" />
</CommandUIDefinition>
<CommandUIDefinition
Location="Ribbon.Calendar.Events.Share.Controls._children">
<Button Id="Muhimbi.SharePoint.Audit.Ribbon.ListItem.Share.ViewAuditLog.Button"
Command="Muhimbi.SharePoint.Audit.Ribbon.ListItem.Share.ViewAuditLog.Button.Command"
Image16by16="/_layouts/images/Muhimbi.SharePointAudit/Report16.gif"
Image32by32="/_layouts/images/Muhimbi.SharePointAudit/Report.gif"
LabelText="$Resources:MuhimbiAuditProvisioningResources,ECB_ViewAuditLog;"
Sequence="11"
TemplateAlias="o1" />
</CommandUIDefinition>
</CommandUIDefinitions>
<CommandUIHandlers>
<CommandUIHandler
Command="Muhimbi.SharePoint.Audit.Ribbon.ListItem.Share.ViewAuditLog.Button.Command"
CommandAction="javascript:window.location='{SiteUrl}/_layouts/Muhimbi.SharePointAudit.Site/AuditLogViewer.aspx?RequestFrom=listitem&ItemId=' + SP.ListOperation.Selection.getSelectedItems()[0].id + '&ListId={ListId}&Source=' + escape(window.location)"
EnabledScript="javascript:function singleEnable()
{
var items = SP.ListOperation.Selection.getSelectedItems();
var ci = CountDictionary(items);
return (ci == 1);
}
singleEnable();" />
</CommandUIHandlers>
</CommandUIExtension>
</CustomAction>
OTHER TIPS
I used a slightly different method. I only had to use one definition for the button to be added to all the different list types now and in the future.
http://djeeg.blogspot.com/2011/01/ribbon-customaction-on-all-lists.html
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange