SharePoint
lets you customize just about anything, and one of the things I have
used in various features a few times is a custom action in the dropdown
menu for list items. Here I will briefly go through how to define a
custom action in a feature.

This
dropdown menu is known as the Edit Control Block (ECB), and it is one
of the many places SharePoint lets you define a custom action.
In
this example, my feature will create a document library, and associate
a custom action with it. Tthe action will allow a user to send the
document off to an email recipient to be reviewed. It does this by
directing the browser to a custom layout page, and passing the library
and list item guid's in the querystring. This page has controls on it
enabling the user to create and send an email, and it attaches a copy
of the document to it (Note: I haven't included the code for this
custom layout page in this posting - holler if you want it).
The list and the custom action are defined in my feature's "Elements.xml":
<!-- List instance deefinition -->
<ListTemplate
Name="ListNameGoesHere"
Type="101"
BaseType="1"
OnQuickLaunch="False"
FolderCreation="False"
SecurityBits="11"
DisplayName="List Display Name goes here"
Description="List description goes here."
NoCrawl="True"
AllowDeletion="True"
DisallowContentTypes="False"
DisableAttachments="False"
DontSaveInTemplate="True"
EnableModeration="False"
MultipleTypes="False"
Image="/_layouts/images/itdl.gif">
</ListTemplate>
<!-- Send Item for Review action -->
<CustomAction
Id="{9438f6c5-8074-4524-a73d-b605dda61243}"
RegistrationType="List"
RegistrationId="101"
Location="EditControlBlock"
Sequence="111"
Title="Send Item for Review">
<UrlAction
Url="{SiteUrl}/_layouts/ReviewItem.aspx?List={ListId}&ID={ItemId}"/>
</CustomAction>
The
<ListInstance> element creates the document library to which the
action will be associated. I am using the out-of -the-box document
library template here (101), but you could of course do the same thing
with a list instance based of your own list template.
The settings I have specified in the <CustomAction> element are as follows:
- Id - a Guid for this action
- RegistrationType - Specifies which type of object
this action will be associated to, in this case a list, though it could
be a file type, or content type, etc.
- RegistrationId - The identifier of the object specified above to link this action to. In this case, the TemplateId of the list.
- Location - Where this custom action will be added
- in this case the ECB - though there are quite a few other places
where you can add a custom action.
- Sequence - The order in which the custom action(s)
will be displayed. Presumably you could use this to put your action
lower in the list the the out-of-the-box ones, though I have only used
it to order my actions (if I have multiple ones) at the top of this
list.
- Title - the text to be displayed on your action
- UrlAction - this is a sub-element of the
CustomAction element, and specifies the page where the browser will be
directed to when this action is triggered. the URL I am redirecting to
uses a few SharePoint “tokens”. Windows SharePoint Services supports
the following tokens with which to start a relative URL:
- ~site - Web site (SPWeb) relative link.
- ~sitecollection - site collection (SPSite) relative link.
In addition, you can use the following tokens within a URL:
- {ItemId} - Integer ID that represents the item within a list.
- {ItemUrl} - URL of the item being acted upon.
- {ListId} - GUID that represents the list.
- {SiteUrl} - URL of the Web site (SPWeb).
- {RecurrenceId} - Recurrence index. This token is not supported for use in the context menus of list items
So, when the user selects my action “Send Item For Review”, it
will direct the browser to …/_layouts/ReviewItem.aspx, passing the list
ID and list item ID in the querystring. This page has controls on it
that allow the user to enter the email details, and send it off (with
the item attached) for review.
You can use custom actions all over the place - the ECB, the “Site Actions” menu, etc. Further reading on custom actions:
-
-
-
-
-
-
-
-
-
Following a request in the comments for an example of the page my custom action was passing to - I have *very quickly* cleaned this page of any customer specific information, and added it in the zip attached to this post. It is simply an ASPX page and the code-behind (CS) file - the ASPX is deployed to a directory under TEMPLATE/LAYOUTS, and is referenced (as shown above) by the site action. PLEASE NOTE: I have not checked if these would work following my quick cleaning, but think they are an adequate example of how you parse the URL to create objects for the given SPWeb / SPList etc. Enjoy!