Export (0) Print
Expand All
Expand Minimize

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

Windows SharePoint Services 3

Visual How To

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

Ted Pattison, Critical Path Training

May 2007

Overview

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.

Code It

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.

<Feature 
  Id="AA929AFF-4602-4d7f-A501-B80AC9A4BB52" 
  Title="A Sample Feature: Item Auditing"
  Description="A sample feature with an ECB menu item"
  Scope="Site" 
  xmlns="http://schemas.microsoft.com/sharepoint/">
  <ElementManifests>
    <ElementManifest Location="elements.xml" />
  </ElementManifests>
</Feature>

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.

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <CustomAction 
    Id="ApplicationPage1"
    GroupId="SiteActions"
    Location="Microsoft.SharePoint.StandardMenu"
    Sequence="2000"
    Title="Hello World Application Page"
    Description="Getting up and going with inline code" >
     <UrlAction Url="~site/_layouts/Litware/ApplicationPage1.aspx"/>
  </CustomAction>
</Elements>
Read It

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.

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <CustomAction 
    Id="ApplicationPage1"
    GroupId="SiteActions"
    Location="Microsoft.SharePoint.StandardMenu"
    Sequence="2000"
    Title="Hello World Application Page"
    Description="Getting up and going with inline code"
    RequireSiteAdministrator="True" >
     <UrlAction Url="~site/_layouts/Litware/ApplicationPage1.aspx"/>
  </CustomAction>
</Elements>

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.

See It

Creating A Feature For The Site Actions Menu

Watch the Video

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

Explore It
Show:
© 2014 Microsoft