How to Add Menu Items to SharePoint with Features, Custom Actions, and Custom Action GroupsPosted: June 28, 2008
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.
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.
What about the “Site Actions”, list or library “Actions” and “Settings” menus? These, like most other SharePoint menus, can also be configured via CustomActions.
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
- Browse to the file system Feature folder located in “C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES\”
- 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
- Open the folder and create a new empty file naming it FEATURE.xml
- Open the file and paste the following XML, replacing NEWGUID with a newly generated GUID.
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.
- Save and close the file
- Create another file and name it “CustomMenuItem.xml”, we’ve specified this as an Elements Manifest file in our feature definition.
- Open the file and paste the following XML
- 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.
- 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
- Save and close the file.
- 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\"
- Browse to the Site Settings page of one of the SharePoint sites in Internet Explorer and click on the "Site Features" link
- Click the "Activate" button next to the new feature
- Go back to the Site Settings page to see your new menu item / custom action.
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:
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: