How to Add Menu Items to SharePoint with Features, Custom Actions, and Custom Action Groups

In my previous post, “Hidden SharePoint Lists, Fields, and Other Advanced List Settings”, I demonstrated how we can develop a custom application page to easily expose and modify list and field settings. But once the custom application page has been created, how do we expose it to our users? Ideally we would create links to our Application Pages by adding new menu item entries to the SharePoint Site Settings and Site Actions menus. Fortunately, SharePoint allows us to do just that via Features and the CustomActionGroup and CustomAction elements.

The CustomAction element refers to the actual link or menu item.

image

The CustomActionGroup element, as Microsoft puts it, “contains the core definition for a grouping of custom actions.” Such as when you see a group of links or menu items grouped together in the “Operations” and “Application Management” pages of the Central Administration site.

image

What about the “Site Actions”, list or library “Actions” and “Settings” menus? These, like most other SharePoint menus, can also be configured via CustomActions. 

image image

The following steps demonstrate how we can use features and CustomActions to add a new menu item to the Site Settings page.

Creating the Feature

  1. Browse to the file system Feature folder located in “C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES\”
  2. Create a new folder for your feature. In my case I will call it “AdvancedListSettings” as I will use the feature to add a link to the Custom Application Page I created in my previous post; Hidden SharePoint Lists, Fields, and other Advanced List Settings
  3. Open the folder and create a new empty file naming it FEATURE.xml

    image

  4. Open the file and paste the following XML, replacing NEWGUID with a newly generated GUID. 

    <Feature xmlns="http://schemas.microsoft.com/sharepoint/”
      Id=”NEWGUID”
      Title=”Advanced List Settings Menu”
      Description=”This Feature adds a new menu item to the Site Settings page”
      Hidden=”FALSE”
      Scope=”Web”
      Version=”1.0.0.0″>
       
           
       

    I like to call this file the “feature definition file”. It contains the general settings of our feature such as; title, description, feature scope, and whether or not the feature is hidden; but it doesn’t necessarily contain any of the “meat” or instructions for the feature, we’ll put those in our Elements Manifest file which we’ll create next.

     

  5. Save and close the file
  6. Create another file and name it “CustomMenuItem.xml”, we’ve specified this as an Elements Manifest file in our feature definition.
  7. Open the file and paste the following XML

    <Elements
        xmlns=”http://schemas.microsoft.com/sharepoint/”>
        <CustomAction
            Id=”AdvancedListSettings”
            GroupId=”SiteAdministration”
            Location=”Microsoft.SharePoint.SiteSettings”
            RequireSiteAdministrator=”TRUE”
            Sequence=”1″
            Title=”Advanced List Settings”>
            <UrlAction
                Url=”_layouts/AdvancedListSettings.aspx” />
       

     

  8. Looking at out CustomAction element the attributes break down as follows:
    • ID – The ID specifies a unique identifier for the custom action, keep in mind that it must be unique, you may want to use a GUID.
    • GroupID – Identifies an action group that contains the action, for example, "SiteManagement". If contained within a custom action group, the value of the GroupId attribute must equal the group ID of the CustomActionGroup element.
    • Location – Specifies the location of this custom action. In this example we specified “Microsoft.SharePoint.SiteSettings", which tells SharePoint to create the custom action in the Site Settings Page.

      Note: Click here for the default list of Locations and ID’s

    • Sequence – Indicates what position the custom action should be placed in regards to other custom actions that may be in the same group.
    • Title – Gives it the text to display
  9. Save and close the file.
  10. Open the command prompt and execute the following command to install the feature:

    stsadm -o installfeature -file AdvancedListSettings

    Where “AdvancedListSettings” is the name of the new feature folder in “C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES\”

  11. Browse to the Site Settings page of one of the SharePoint sites in Internet Explorer and click on the “Site Features” link

     image

  12. Click the “Activate”  button next to the new feature

    image

  13. Go back to the Site Settings page to see your new menu item / custom action.

    image 

To create a new section in the site settings page and have the link appear in that new section, the elements manifest file (i.e. CustomMenuItem.xml in this example) would have too look as follows:

<Elements
    xmlns=”http://schemas.microsoft.com/sharepoint/”>
    <CustomActionGroup
        Id=”SiteListandLibrarySettings”
        Location=”Microsoft.SharePoint.SiteSettings”
        Title=”Site List and Library Settings”
        Sequence=”1″ />
    <CustomAction
            Id=”AdvancedListSettings”
            GroupId=”SiteListandLibrarySettings”
            Location=”Microsoft.SharePoint.SiteSettings”
            RequireSiteAdministrator=”TRUE”
            Sequence=”1″
            Title=”Advanced List Settings”>
            <UrlAction
                Url=”_layouts/AdvancedListSettings.aspx” />
   

Notice the new CustomActionGroup element, it uses many of the same attributes of the CustomAction element. The GroupID attribute of the CustomAction element now references the ID of newly created CustomActionGroup.

For additional information see Custom Action Definitions in the SharePoint General Reference section of the MSDN:
http://msdn.microsoft.com/en-us/library/ms465980.aspx

Technorati Tags: SharePoint, WSS, MOSS, FEATURES

About these ads

7 Comments on “How to Add Menu Items to SharePoint with Features, Custom Actions, and Custom Action Groups”

  1. Brent says:

    Great Job!

  2. Stuart says:

    Hi Rafelo,Do you know how I can create a new group within the Site Actions menu? I want to add a few new links to the SiteActions menu and they would logically be grouped together but I can’t quite work it out.

  3. Rafelo says:

    Hey Stuart, to add menu items to the Site Actions menu; use <>Microsoft.SharePoint.StandardMenu<> for the Location and <>SiteActions<> for the GroupID in the elements.xml file.<><> The following MSDN article gives you the whole list of Locations and GroupIDs that are available: < HREF="http://msdn.microsoft.com/en-us/library/bb802730.aspx" REL="nofollow">http://msdn.microsoft.com/en-us/library/bb802730.aspx<>

  4. Stuart says:

    I’ve got that this far, but I was hoping to have them grouped similar to the “View Reports” group and then have my custom actions as a sub menu for that.

  5. Rafelo says:

    Hey Stuart, Jan Tielens has posting on how to add “fly out” or dynamic menus items to SharePoint. It requires some coding of a Control Assembly and Control Class that you then specify as part of your CustomAction. See < HREF="http://weblogs.asp.net/jan/archive/2008/05/08/creating-hierarchical-menus-with-a-customaction-in-sharepoint.aspx" REL="nofollow">http://weblogs.asp.net/jan/archive/2008/05/08/creating-hierarchical-menus-with-a-customaction-in-sharepoint.aspx<>

  6. Rafelo says:

    Hey everybody, I’ll be giving a SharePoint Developer Training Weekend Crash Course this upcoming March for anybody who is interested. You can check out the full announcement and agenda at < HREF="http://www.rafelo.com/sharepointtraining" REL="nofollow">http://www.rafelo.com/sharepointtraining<>

  7. RupaliK says:

    Hi Rafelo,
    Thanks for the good article.
    I could create CustomActionGroup with location as Microsoft.SharePoint.SiteSettings. Although when I try to create a CustomActionGroup with Location as Microsoft.SharePoint.ListEdit.DocumentLibrary,
    It does not work.

    Are there any Location limitations on CustomActionGroup? Please let me know if you have any idea.

    Thanks in Advance,


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.