
Deploy di una custom action nella ribbon di SharePoint
Tramite feature è possibile deployare delle custom action per SharePoint 2010 da posizionare nella ribbon o sul menù contestuale (ECB).
L'xml da inserire nella feature per avere una voce nel menù contestuale è il seguente:
Per avere la stessa funzionalità anche nella ribbon puoi usare questo xml:
I tag disponibili nella CommandAction sono:
Ed infine una custom action generica sulla ribbon non legata a uno specifico list item:
Vedi anche Custom Action Definition Schema
    L'xml da inserire nella feature per avere una voce nel menù contestuale è il seguente:
XML
<!-- custon actions ECB -->
<CustomAction Id="SgartEdit"
    RegistrationType="ContentType"
    RegistrationId="0x010068EBA7A1B34244179CA55599D440E1E0"
    Location="EditControlBlock"
    Sequence="450"
    Title="Edit"
    Description="Edit single"
    Rights="EditListItems"
    ImageUrl="/_Layouts/images/sgart/edit16.png">
    <UrlAction Url="javascript:location.href='{SiteUrl}/_Layouts/sgart/Edit.aspx?SgartID={ItemId}&Source={Source}'" />
</CustomAction>
Attenzione di tutti gli & (ampersand) nella url va fatto l'escape & amp;
In questo caso la voce è associata solo a uno specifico content type (attributi RegistrationType e RegistrationId).Per avere la stessa funzionalità anche nella ribbon puoi usare questo xml:
XML
<CustomAction Id="SgartEditRibbon" 
  RegistrationType="ContentType"
  RegistrationId="0x010068EBA7A1B34244179CA55599D440E1E0"
  Location="CommandUI.Ribbon.ListView" 
  Title="Edit Questions">
  <CommandUIExtension>
    <CommandUIDefinitions>
      <CommandUIDefinition Location="Ribbon.ListItem.Actions.Controls._children">
        <Button Id="Ribbon.Items.Actions.EditQuestion" 
            Sequence="100"
            Command="Sgart_Cmd_Edit"
            Image32by32="~site/_layouts/images/sgart/edit32.png"
            Image16by16="~site/_layouts/images/sgart/edit16.png"
            LabelText="Edit Questions"
            TemplateAlias="o1" />
      </CommandUIDefinition>
    </CommandUIDefinitions>
    <CommandUIHandlers>
      <CommandUIHandler
       Command="Sgart_Cmd_Edit"
       CommandAction="javascript:location.href='{SiteUrl}/_Layouts/sgart/Edit.aspx?SgartID={SelectedItemId}&Source={Source}'"
       EnabledScript="javascript:
         function enableSgartCmdEdit()
         {
           var items = SP.ListOperation.Selection.getSelectedItems();
           return (items.length == 1);
         }
         enableSgartCmdEdit();"
       />
    </CommandUIHandlers>
  </CommandUIExtension>
</CustomAction>
Attenzione, le lettere presenti nel RegistrationId devono exxere tutte maiuscole ad eccezione della x. 
Quindi questo è corretto: 0x010068EBA7A1B34244179CA55599D440E1E0
questi no: 0x010068EBA7A1B34244179CA55599d440e1e0, 0X010068EBA7A1B34244179CA55599D440E1E0
Quindi questo è corretto: 0x010068EBA7A1B34244179CA55599D440E1E0
questi no: 0x010068EBA7A1B34244179CA55599d440e1e0, 0X010068EBA7A1B34244179CA55599D440E1E0
I tag disponibili nella CommandAction sono:
- {ItemId} : ID (GUID) taken from the list view
- {ItemUrl} : Web-relative URL of the list item (Url)
- {RecurrenceId} : ID of a recurrent item (RecurrenceID)
- {SiteUrl} : The fully qualified URL to the site (Url)
- {ListId} : ID (GUID) of the list (ID)
- {ListUrlDir} : Server-relative URL of the site plus the list's folder
- {Source} : Fully qualified request URL
- {SelectedListId} : ID (GUID) of the list that is currently selected from a list view
- {SelectedItemId} : ID of the item that is currently selected from the list view
Ed infine una custom action generica sulla ribbon non legata a uno specifico list item:
XML
<CustomAction Id="SgartCopyRibbon"
  RegistrationType="ContentType"
  RegistrationId="0x010068EBA7A1B34244179CA55599D440E1E0"
  Location="CommandUI.Ribbon.ListView"
  Title="Copy from">
  <CommandUIExtension>
    <CommandUIDefinitions>
      <CommandUIDefinition Location="Ribbon.ListItem.New.Controls._children">
        <Button Id="Ribbon.Items.New.SgartCopy"
            Sequence="110"
            Command="Sgart_Cmd_Copy"
            Image32by32="/_layouts/images/sgart/copy32.png"
            Image16by16="/_layouts/images/sgart/copy16.png"
            LabelText="Copy"
            TemplateAlias="o1" />
      </CommandUIDefinition>
    </CommandUIDefinitions>
    <CommandUIHandlers>
      <CommandUIHandler
       Command="Sgart_Cmd_Copy"
       CommandAction="javascript:location.href='{SiteUrl}/_Layouts/sgart/CopyFrom.aspx?SgartListID={ListId}&Source={Source}'"
       />
    </CommandUIHandlers>
  </CommandUIExtension>
</CustomAction>
Vedi anche Custom Action Definition Schema