Click to Rate and Give Feedback
MSDN
MSDN Library
Web Development
Visual How Tos
 Creating a Feature for an Entry Con...

  Switch on low bandwidth view
Community Content
In this section
Statistics Annotations (0)
Creating a Feature for an Entry Control Block Item in Windows SharePoint Services 3.0
Visual How To

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

Ted Pattison, Ted Pattison Group

May 2007

Overview

You can add a custom menu item for an entry control block to a list item or a document in Microsoft Windows SharePoint Services 3.0 by creating a Feature with a CustomAction element. In this way, you can add custom commands to the default SharePoint user interface. These menu commands allow users to perform custom operations on items and documents. For example, you can create a custom menu item for an entry control block for a list item or document that redirects the user to a custom application page. Use this as a starting point to create business solutions that provide an intuitive user interface to automate domain-specific tasks on list items and documents.

Code It

First, create a custom Feature. You can define the Feature at any scope, but typically it is defined at either the site-collection scope level or site scope level. The following Feature is defined at the level of a site-collection scope (that is, Scope="Site") and includes a reference to another CAML file named elements.xml.

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

Defining a Custom Action

Use the CustomAction element to define various types of menu items and links within the default SharePoint user interface. The following CustomAction element adds a custom menu item to the entry control block menu for any document within all document libraries. This is accomplished by specifying the RegistrationType attribute of a List element and a RegistrationId value of 101. This is the type identifier for the default SharePoint document library type.

Xml
<CustomAction 
  Id="ItemAuditing.ECBItemMenu"
  RegistrationType="List" 
  RegistrationId="101"
  ImageUrl="/_layouts/images/GORTL.GIF"
  Location="EditControlBlock"
  Sequence="300"
  Title="View Audit History" >
  <UrlAction
    Url="~site/_layouts/ItemAudit.aspx
    ?ItemId={ItemId}&amp;ListId={ListId}"/>
</CustomAction>
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 ItemAudit.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 URL of the current site.

~site/_layouts/ItemAudit.aspx

When you redirect the user to a custom application page from a menu item for the entry control block of a list item or document, you must typically pass query strings to the custom application page so that it programmatically creates the associated SPList object and SPListItem object. Windows SharePoint Services supports two other dynamic tokens: {ListId} and {ItemId}. Windows SharePoint Services replaces these tokens with the GUIDs that identify the list or the document library, and the integer identifier for the item or the document.

~site/_layouts/ItemAudit.aspx?ItemId={ItemId}&amp;ListId={ListId}

This approach allows a custom application page, such as ItemAudit.aspx, to retrieve the ListId and the ItemId values during its initialization so that it can program against and automate tasks for the item or document that the user is interested in.

See It WSS3 Creating A Feature For An ECB Item splash

Watch the Video

Video Length: 00:04:11

File Size: 7.00 MB WMV

Explore It
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Create Custom Actions for specific content type or specific list      Gafy ... Thomas Lee   |   Edit   |   Show History

Is is possible to create a custom action for a specific content type. I did the following but i did not work

<CustomAction
Id="ItemAuditing.DisplayFormToolbar"
RegistrationType="ContentType"
RegistrationId ="0x01006A717F34C81442d1944A38D0CC7F7800"
ImageUrl="/_layouts/images/GORTL.GIF"
Location="DisplayFormToolbar"
Sequence="120"
Title="Approve" >
<UrlAction
Url="~site/_layouts/ItemAudit.aspx?action=approve&amp;ItemId={ItemId}&amp;ListId={ListId}"/>
</CustomAction>

where the RegistrationId ="0x01006A717F34C81442d1944A38D0CC7F7800" is the unique id for the content type I created.

In the meanwhile, when I change that RegistrationId ="0x01" to refer to the item content type everything works just fine, but the approve button shows for every item in every list.

I just want to applly that custom action for a specific content type then apply that contet type to a list, so that the approve button will only show for the items in that list.

Please advice if that is possible or not.

Flag as ContentBug
QueryString arguments aren't quite right      mattpb ... Thomas Lee   |   Edit   |   Show History
In my experience, if you want to use the built-in context ability of a layouts page, the querystring arguments need to be ID and List instead of ItemId and ListId, respectively.

I believe the example for the UrlAction should read:

<UrlAction Url="~site/_layouts/ItemAudit.aspx?ID={ItemId}&amp;List={ListId}"/>
Tags What's this?: Add a tag
Flag as ContentBug
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker