Share via


How to: Add Actions to the User Interface

This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This page may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.

Using Features makes it easy to add actions to menus of the user interface in Windows SharePoint Services. This example shows how to add actions to various menus through a Feature and how to activate it within the deployment.

Location and Group ID

To define a custom action for a particular menu, you must identify the menu by setting the location to the appropriate Windows SharePoint Services namespace, and by using the ID that Windows SharePoint Services uses to identify the specific location.

For example, to add a custom action to the Site Settings page, set the Location attribute of the CustomAction element to Microsoft.SharePoint.SiteSettings.and specify a particular area within the page through the GroupId attribute.

Different actions may require using different CustomAction attributes to identify the menu in which to place a custom menu item. But you may also need to specify other parameters for the action, for example, to specify a version, user permissions required to perform the action, or placement in relation to existing actions in the menu. The custom actions of the following example show a variety of attributes.

See Default Custom Action Locations and IDs for a list of the default custom action IDs and locations that are used in an installation of Windows SharePoint Services.

URL Tokens

Windows SharePoint Services supports the following tokens with which to start a relative URL:

~site - Web site (SPWeb) relative link.

~sitecollection - site collection (SPSite) relative link.

In addition, you can use the following tokens within a URL:

{ItemId} - Integer ID that represents the item within a list.

{ItemUrl} - URL of the item being acted upon. Only work for documents in libraries. [Not functional in Beta 2]

{ListId} - GUID that represents the list.

{SiteUrl} - URL of the Web site (SPWeb).

{RecurrenceId} - Recurrence index. This token is not supported for use in the context menus of list items.

Procedures

To add actions to the user interface in a site collection

  1. Create a UserInterfaceCustomActions folder within the setup directory at the following location: C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES.

  2. Create a Feature.xml file in the new UserInterfaceCustomActions folder to provide the manifest for the feature, such as the following.

    <?xml version="1.0" encoding="utf-8" ?>
    <Feature Id="GUID" 
        Title="UI Custom Actions"
        Description="This example shows how you can customize various areas inside Windows SharePoint Services."
        Version="1.0.0.0"
        Scope="Site"
        xmlns="http://schemas.microsoft.com/sharepoint/">
      <ElementManifests>
        <ElementManifest Location="UICustomActions.xml" />
      </ElementManifests>
    </Feature>
    
  3. To replace the GUID placeholder in the previous Id attribute, generate a GUID by running guidgen.exe located in the Local_Drive:\Program Files\Microsoft Visual Studio 8\Common7\Tools directory.

  4. Create a UICustomActions.xml file to define elements for the various actions included within the feature. For the sake of example, the URL for each action points to an .aspx file and passes it a value that identifies the source of the request, as follows:

    <?xml version="1.0" encoding="utf-8" ?>
    <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
    <!-- Document Library Toolbar New Menu Dropdown -->
      <CustomAction Id="UserInterfaceCustomActions.DocLibNewToolbar"
        RegistrationType="List"
        RegistrationId="101"
        GroupId="NewMenu"
        Rights="ManagePermissions"
        Location="Microsoft.SharePoint.StandardMenu"
        Sequence="1000"
        Title="MY DOCLIB NEW MENU TOOLBAR BUTTON">
        <UrlAction Url="/_layouts/CustomActionsHello.aspx?NewMenu"/>
      </CustomAction>
    <!-- Document Library Toolbar Upload Menu Dropdown -->
      <CustomAction Id="UserInterfaceCustomActions.DocLibUploadToolbar"
        RegistrationType="List"
        RegistrationId="101"
        GroupId="UploadMenu"
        Rights="ManagePermissions"
        Location="Microsoft.SharePoint.StandardMenu"
        Sequence="1000"
        Title="MY DOCLIB UPLOAD MENU TOOLBAR BUTTON">
        <UrlAction Url="/_layouts/CustomActionsHello.aspx?UploadMenu"/>
      </CustomAction>
    <!-- Document Library Toolbar Actions Menu Dropdown -->
      <CustomAction Id="UserInterfaceCustomActions.DocLibActionsToolbar"
        RegistrationType="List"
        RegistrationId="101"
        GroupId="ActionsMenu"
        Location="Microsoft.SharePoint.StandardMenu"
        Sequence="1000"
        Title="MY DOCLIB ACTIONS MENU TOOLBAR BUTTON">
        <UrlAction Url="/_layouts/CustomActionsHello.aspx?ActionsMenu"/>
    </CustomAction>
    <!-- Document Library Toolbar Settings Menu Dropdown -->
      <CustomAction Id="UserInterfaceCustomActions.DocLibSettingsToolbar"
        RegistrationType="List"
        RegistrationId="101"
        GroupId="SettingsMenu"
        Location="Microsoft.SharePoint.StandardMenu"
        Sequence="1000"
        Title="MY DOCLIB SETTINGS MENU TOOLBAR BUTTON">
        <UrlAction Url="/_layouts/CustomActionsHello.aspx?SettingsMenu"/>
      </CustomAction>
    <!-- Site Actions Dropdown -->
      <CustomAction Id="UserInterfaceCustomActions.SiteActionsToolbar"
        GroupId="SiteActions"
        Location="Microsoft.SharePoint.StandardMenu"
        Sequence="1000"
        Title="MY SITE ACTIONS BUTTON">
        <UrlAction Url="/_layouts/CustomActionsHello.aspx?SiteActions"/>
      </CustomAction>
    <!-- Per Item Dropdown (ECB)-->
      <CustomAction 
        Id="UserInterfaceCustomActions.ECBItemToolbar"
        RegistrationType="List"
        RegistrationId="101"
        Location="EditControlBlock"
        Sequence="106"
        Title="MY ECB ITEM">
        <UrlAction Url="/_layouts/CustomActionsHello.aspx?ECBItem"/>
      </CustomAction>
    <!-- Display Form Toolbar -->
      <CustomAction 
        Id="UserInterfaceCustomActions.DisplayFormToolbar"
        RegistrationType="List"
        RegistrationId="101"
        Location="DisplayFormToolbar"
        Sequence="106"
        Title="MY DISPLAY FORM TOOLBAR">
        <UrlAction Url="/_layouts/CustomActionsHello.aspx?DisplayFormToolbar"/>
      </CustomAction>
    <!-- Edit Form Toolbar -->
      <CustomAction 
        Id="UserInterfaceCustomActions.EditFormToolbar"
        RegistrationType="List"
        RegistrationId="101"
        Location="EditFormToolbar"
        Sequence="106"
        Title="MY EDIT FORM TOOLBAR">
        <UrlAction Url="/_layouts/CustomActionsHello.aspx?EditFormToolbar"/>
      </CustomAction>
    <!-- Site Settings -->
      <CustomAction 
        Id="UserInterfaceCustomActions.SiteSettings"
        GroupId="Customization"
        Location="Microsoft.SharePoint.SiteSettings"
        Sequence="106"
        Title="MY SITE SETTINGS LINK">
        <UrlAction Url="/_layouts/CustomActionsHello.aspx?Customization"/>
      </CustomAction>
    <!-- Content Type Settings -->
      <CustomAction 
        Id="UserInterfaceCustomActions.ContentTypeSettings"
        GroupId="General"
        Location="Microsoft.SharePoint.ContentTypeSettings"
        Sequence="106"
        Title="MY CONTENT TYPE SETTINGS LINK">
        <UrlAction Url="/_layouts/CustomActionsHello.aspx?General"/>
      </CustomAction>
    </Elements>
    

    Other common GroupId values that can be used include ViewToolbar, ViewSelectorMenu, and PersonalActions (Welcome menu)

  5. Add a CustomActionsHello.aspx file such as the following in the \TEMPLATE\LAYOUTS directory to serve as target for the links created in the previous step.

    <%@ Page Language="C#"  Inherits="System.Web.UI.Page"%>
    <%
    string clientQuery = Page.ClientQueryString;
    if (clientQuery == "NewMenu")
    {
        Response.Write("You came from the new document menu.");
    }
    else if (clientQuery == "UploadMenu")
    {
        Response.Write("You came from the upload menu.");
    }
    else if (clientQuery == "ActionsMenu")
    {
        Response.Write("You came from the actions menu.");
    }
    else if (clientQuery == "SettingsMenu")
    {
        Response.Write("You came from the settings menu.");
    }
    else if (clientQuery == "SiteActions")
    {
        Response.Write("You came from the Site Actions menu.");
    }
    else if (clientQuery == "ECBItem")
    {
        Response.Write("You came from the document's context menu.");
    }
    else if (clientQuery == "DisplayFormToolbar")
    {
        Response.Write("You came from the display item properties form.");
    }
    else if (clientQuery == "EditFormToolbar")
    {
        Response.Write("You came from the edit item properties form.");
    }
    else if (clientQuery == "Customization")
    {
        Response.Write("You came from the Site Settings menu.");
    }
    else if (clientQuery.StartsWith("General"))
    {
        Response.Write("You came from the Content Type Settings menu.");
    }
    %>
    
  6. At a command prompt, type the following commands to install the Feature in the deployment, activate the Feature on a specified subsite, and then reset Microsoft Internet Information Services (IIS) so that the changes can take effect.

       a. stsadm -o installfeature -filename UserInterfaceCustomActions\feature.xml
       b. stsadm -o activatefeature -filename UserInterfaceCustomActions\feature.xml -url http://Server/Site/Subsite
       c. iisreset
    
  7. To see the various custom actions that you have added, navigate to the following locations from the home page of a Web site in the site collection:

    1. Click Site Actions to see the new action on the Site Actions menu.

    2. Click Site Settings on the Site Actions menu to see a new action in the Look and Feel section of the Site Settings page.

    3. Navigate to a document library and open each menu on the toolbar to see a new action on each menu.

    4. In a document library that contains items, click the down arrow for an item to see the new action on the edit control block menu.

    5. On the edit control block menu for an item, click View Properties and Edit Properties to see new actions on the Display form and Edit form toolbars.

See Also

Concepts

Default Custom Action Locations and IDs