Creating a Feature for the Site Actions Menu in Windows SharePoint Services 3.0

Applies to: Microsoft Windows SharePoint Services 3.0, Microsoft Office SharePoint Server 2007, Microsoft Visual Studio 2005

Ted Pattison, Critical Path Training

May 2007

You can add a custom menu item to the default Site Actions menu in Microsoft Windows SharePoint Services by creating a Feature with a CustomAction element. In this way, you can add custom commands to the default SharePoint user interface. These commands are available to users as they move between pages on a SharePoint site. When you create a Site Actions menu item, you can configure it to redirect the user to any URL. For example, you can redirect the user to another Web site. You can also redirect users to a custom application page that allows them either to see a custom display of data, or to perform custom operations on the content within the current site.

First, create a custom Feature. You must define the Feature at either a site-collection scope level or site scope level. If the Feature is defined at a site-collection scope level (that is, Scope="Site"), the resulting menu item appears in the Site Actions menu for every site within the current site collection. If the Feature is defined as site scope (that is, Scope="Web"), the resulting menu item appears in the Site Actions menu for only the specific sites in which it is activated. The following Feature is defined at site-collection scope and includes a reference to another CAML file named elements.xml.

Defining a Custom Action for a Site Action menu item

Use the CustomAction element to define various types of menu items and links within the default SharePoint user interface. The following CustomAction element is included within a CAML file named elements.xml to add a custom menu item to the Site Actions menu that redirects the user to a custom application page.

When you create a CustomAction element, you must add an inner UrlAction element that contains a Url attribute. When you redirect the user to an application page, such as ApplicationPage1.aspx, you must consider whether you want the application page to run inside the context of the current site or the current site collection. In the following example, the dynamic token ~site is added to the beginning of the URL. When Windows SharePoint Services parses this CustomAction element and creates the menu item, it replaces ~site with the actual URL of the current site.

~site/_layouts/Litware/ApplicationPage1.aspx

When you create the element for a custom menu item in the Site Actions menu, you have the option to configure it so that it is shown only to users who have administrative permissions. Note in the following example the addition of a new attribute named RequireSiteAdministrator.

When you add the RequireSiteAdministrator attribute, Windows SharePoint Services does not show the menu item to users who do not have administrative permissions. For a CustomAction element in a Feature that is scoped at the site-collection level, the menu item appears only for the site collection owner or administrator. For a CustomAction element in a Feature that is scoped at the site level, the menu item appears only to those who have administrative permissions within the current site.

Watch the Video

Length: 5:19 | Size: 9.39 MB | Type: WMV