Adding ribbon Custom Actions to a Site Assets library

Recently I needed to add a Custom Action as a ribbon button for a Site Assets library in a provided-hosted SharePoint App. Doing that using Visual Studio is very straight forward. Go through the wizard and action is added to the project. It is, however, NOT going to show up on the ribbon. If you select a List Template and Asset Library, as I did initially, the action will be added for a list template with RegistrationID=”851″ which should match the list’s BaseTemplate id. However list template id of an Site Assets library is 101 in SharePoint 2013 and id 851 simply does not exist. (See list of available template ids here). So to add custom action to a Site Assets library we need to add it to a List Instance.

Adding Ribbon Custom Action to Site Assets

Adding Ribbon Custom Action to Site Assets

Thankfully Site Assets library is added automatically to most sites templates. Unfortunately, with this approach, if the library does not exist, adding the app will fail.

Here is the action definition that works:

   <CustomAction Id="b4a1c4d7-e288-4dc8-9fb8-74f11bd22040.ImageRibbonCustomActionSA"
                RegistrationType="List"
                RegistrationId="{$ListId:SiteAssets;}"
                Location="CommandUI.Ribbon"
                Sequence="10001"
                Title="$Resources:CustomActionRibbonTitle"
                Rights="EditListItems"
                HostWebDialog="true"
                HostWebDialogHeight="300"
                HostWebDialogWidth="400">
    <CommandUIExtension>
      <CommandUIDefinitions>
        <CommandUIDefinition Location="Ribbon.Documents.Manage.Controls._children">
          <Button Id="Ribbon.Documents.Manage.ImageRibbonCustomActionSAButton"
                  Alt="Resize"
                  Sequence="100"
                  Command="Invoke_ImageRibbonCustomActionSAButtonRequest"
                  LabelText="$Resources:CustomActionRibbonTitle"
                  TemplateAlias="o1"
                  Image32by32="data:image/png;base64,iVBORw0KGgoAAAANSUhEU ...="
                  Image16by16="data:image/png;base64,iVBORw0KGgoAAAANSUhEU ...=" />
        </CommandUIDefinition>
        <CommandUIDefinition Location="Ribbon.DocLibListForm.Edit.Actions.Controls._children">
          <Button Id="Ribbon.DocLibListForm.Edit.Actions.ImageRibbonCustomActionSAButton"
                  Alt="Resize"
                  Sequence="100"
                  Command="Invoke_ImageRibbonCustomActionSAButtonRequest"
                  LabelText="$Resources:CustomActionRibbonTitle"
                  TemplateAlias="o1"
                  Image32by32="data:image/png;base64,iVBORw0KGgoAAAANSUhEU ...="
                  Image16by16="data:image/png;base64,iVBORw0KGgoAAAANSUhEU ...=" />
        </CommandUIDefinition>
      </CommandUIDefinitions>
      <CommandUIHandlers>
        <CommandUIHandler Command="Invoke_ImageRibbonCustomActionSAButtonRequest"
                          CommandAction="~remoteAppUrl/Pages/Default.aspx?{StandardTokens}&amp;SPListItemId={SelectedItemId}&amp;SPListId={SelectedListId}"/>
      </CommandUIHandlers>
    </CommandUIExtension >
  </CustomAction>