128 out of 150 rated this helpful - Rate this topic

How to: Add Actions to the User Interface

Windows SharePoint Services 3

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

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
Works in WSS 3.0 but not in MOSS 2007

All good stuff … My problem is the same as SWEENJ2. I have created the feature, and it works perfectly in WSS 3.0. I try it in MOSS SP1 and it never shows up either functionally or in the Site Collection Feature list. Tried it both on our test MOSS environment and our production. Disappears without a trace … Installs fine, activates fine via STSADM, shows up in some tools, but is missing in the Site Collection Feature list and most certainly doesn’t work …

Can repeat the install successfully in WSS.

Any ideas?

[tfl - 20 09 09] Hi - and thanks for your post. You should post questions like this to the MSDN Forums at http://forums.microsoft.com/msdn or the MSDN Newsgroups at

http://www.microsoft.com/communities/newsgroups/en-us/. You are much more likely get a quicker response using the forums than through the Community Content. For specific help about:
Visual Studio : http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public.vstudio%2C&
Windows : http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public.windows%2C&
SQL Server : http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public.sqlserver%2C&
.NET Framework : http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public.dotnet.framework
PowerShell : http://groups.google.com/group/microsoft.public.windows.powershell/topics?pli=1
All Public : http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public%2C&
SharePoint Custom Action: Execute Code from the EditControlBlock Location
Great stuff,

When you set the EditControlBlock as location for your custom action you will have to follow a slightly different approach to get your own custom code to execute.

See the following tutorial on how to get it working:
http://johanolivier.blogspot.com/2010/01/sharepoint-custom-action-execute-code.html


Custom Action : SiteManager.aspx

Hey Guys, I completely agree with this approach. My Question is some thing else .... Can we get a similar item in the (custom action) in the ECB or Toolbar in sitemanager.aspx in Layouts folder ? If you have any idea please revert back to be ;-) Regards Amith Sasi

[tfl - 20 09 09] Hi - and thanks for your post. You should post questions like this to the MSDN Forums at http://forums.microsoft.com/msdn or the MSDN Newsgroups at

http://www.microsoft.com/communities/newsgroups/en-us/. You are much more likely get a quicker response using the forums than through the Community Content. For specific help about:
Visual Studio : http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public.vstudio%2C&
Windows : http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public.windows%2C&
SQL Server : http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public.sqlserver%2C&
.NET Framework : http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public.dotnet.framework
PowerShell : http://groups.google.com/group/microsoft.public.windows.powershell/topics?pli=1
All Public : http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public%2C&

2 mistakes in this example

There are two mistakes I found.

1. If you use the scope="Site" you cannot activate the feature on a subsite, you'll have to activate it on site collection level or use the scope="Web" in the feature.xml.

2. You cannot use the Type attribute, but this was already found by a previous poster.

Hope it helps.


I created a post about htis on my blog: http://www.dailycode.net/blog/post/Custom-sharepoint-list-item-action.aspx

Token {ItemId} do not work in DiscussionBoard List. WSS3.0

Have you find any solution on this?

I am trying to use {ItemId} token in CustomAction for DiscussionBoard List. While {ListId} token work properly, {ItemId} not work at all.

Here my example:

feature.xml

<?xml version="1.0" encoding="utf-8" ?> 
<Feature Id="5539E0F8-8AA5-41bd-B09F-5DD7F1C99757"
   Title="Settings button" 
   Description="Settings button ..." 
   Version="1.0.0.0" 
   Scope="Web" 
   xmlns="http://schemas.microsoft.com/sharepoint/"> 
   <ElementManifests> 
      <ElementManifest Location="elements.xml" /> 
   </ElementManifests> 
</Feature>

elements.xml:

<?xml version="1.0" encoding="utf-8" ?> 
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<CustomAction Id="IdeaBoardActionsToolbar"
RegistrationType="List"
  GroupId="ActionsMenu"

Location="Microsoft.SharePoint.StandardMenu"

Title="Item Settings">
<UrlAction Url="~site/ItemSettings.aspx?item={ItemId}&amp;list={ListId}" />
</CustomAction>
</Elements>
Action Menu item to a SPECIFIC list

I'm trying to add an item to the ActionsMenu of a specific list. I tried adding it to the content type but this does not appear to be working.

This is what I have. The RegistrationId is the Id of my custom contenttype. The contenttype works great. But I cannot seem to add the custom Actions Menu item. Any ideas?

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<!-- Add Command to List ActionMenu -->
<CustomAction
Id="AssociatePerformanceReviews.ReviewSchedulerActionsMenu"
RegistrationType="ContentType"
RegistrationId="0x010013398AF7FC024ec3A6BC7B32B1E566FF"
ImageUrl="/_layouts/images/AssociatePerformanceReviews/AssocPerfRevs39X39.gif"
GroupId="ActionsMenu"
Location="Microsoft.Sharepoint.StandardMenu"
Sequence="199"
Title="Send Reviewer Notification Email" >
<UrlAction Url="~site/_layouts/AssociatePerformanceReviews/AssociatePerformanceReviews.aspx?ListId={ListId}"/>
</CustomAction>
</Elements>

Works in WSS 3.0 but not in MOSS 2007

Has anyone gotten these custom actions to work in MOSS? The exact same code works great in WSS 3.0, but when I deploy to a MOSS 2007 server, no menus show up at all except for Site Actions | My Site Actions Button.

I need this to work in the Document Library. Specifically, I need to add a menu option to each document in the library.

As I said, works great in WSS Shared Documents, but not in MOSS Document Lib.

Any thoughts?

Thanks.

Helpful Reference for adding Site Settings Actions
The default site settings actions (what you see on _layouts/settings.aspx) are all defined in a Feature. Take a look at SiteSettings.xml in 12\TEMPLATE\FEATURES\SiteSettings on your MOSS 2007 server.
More about Step 2 Above - GUID format

In step 2 above, where it says that you need to replace the GUID in "<Feature Id="GUID" " with a real GUID that you generate, that GUID should be in Registry Format, excluding the curly braces.

You can see this in the example on http://msdn2.microsoft.com/en-us/library/ms475601.aspx where the XML reads: Id="11111111-1111-1111-1111-11111111111"

Aspx. Page Model, token encoding and {ItemId} equivalence in object model

It would be worth exteding this article to comment that:

1. If the .aspx action page is deployed to LAYOUTS directory then code behind model is not supported (all code must be in-line)

2. The {ItemId} is equivalent to ID attribute of the SPListItem ( wouldn´t it be better to use GUID instead as you do with {ListId}? )

3. Mention that {ListId} string will be encoded and that you should use System.Web.HttpUtility.UrlDecode() function in code to decode it.

4. Have a link to article that describes best practice for how to debug custom actions based on in-line aspx pages.

{ListId} Token Bug?

Adding a custom action to ActionsMenu on Microsoft.SharePoint.StandardMenu for List, the {ListId} token in Url of UrlAction gets different data depending on "where the list is".

Here is the way to find this bug:

1) create a feature and deploy it on sharepoint server. for example:

<?xml version="1.0" encoding="utf-8" ?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<CustomAction
Id="Test.ActionsMenu"
RegistrationType="List"
GroupId="ActionsMenu"
Location="Microsoft.SharePoint.StandardMenu"
ImageUrl="/_layouts/images/icon_document.gif"
Sequence="10"
Title="Test"
Description="">
<UrlAction Url="JavaScript:window.location='{SiteUrl}/_layouts/test.aspx?listid={ListId}'"/>
</CustomAction>
</Elements>
2) find a list/document library (suppose its name is ALIST), browse to its default view: ...ALIST/Forms/AllItems.aspx, from Actions menu, click the customAction you setup, note the ListID refers to ALIST listID, that is expected.

3)Create a web part page and save this page in a different document library, add a web part by finding ALIST under Lists and Libraries, from this web part's Full Toolbar, click the same actionmenu, note that ListID refers to the document library where the page is stored, not the list the web part refers to (ALIST)

4) You can also find another list/document library (BLIST), browse to its default view ...BLIST/Forms/AllItems.aspx, edit this page,

add ALIST web part, from its Full Toolbar's Actions Menu, click the custom action, please note the {ListID} now refers to BLIST

Why are tokens only replaced once?!

I encountered the same as Brian Abram. Its a mess!! I needed the {ItemId} two times in an UrlAction. It simply does not work!!

I hope there will soon be a service pack updating all the small bugs!

Edit: I found an ugly way to bypass this flaw: <UrlAction Url="javascript:function process(){var site='{SiteUrl}';var item={ItemId};window.location.href=site+'/Lists/MyList/NewForm.aspx?ID='+item+'&amp;Source='+site+'/Lists/myOtherList/DispForm.aspx?ID='+item;};process();"/>

URL Tokens can only be used once
SharePoint will not replace multiple tokens of the same type. If you have a URL that needs the SiteURL twice (say, with an InfoPath form that needs the location of the form as well as the source to return to), then the second URL token won't be generated.
How to add a "Print List" option to the actions menu of all lists
Example for Per Item Dropdown is wrong

The Per Item Dropdown (ECB) example in Lightup.xml is wrong. Delete the line containing Type="ECBItem" and it will work.

The Container element does not have an attribute named type. stsadm complains about the line and refuses to install. Removing the line fixes things.