Share via


Step 2: Create the Edit Control Block Menu Item

Applies to: SharePoint Server 2010

This topic shows how to modify the list item context menu, also known as the Edit Control Block (ECB) menu, to include an item that initiates the Word Automation Services document conversion job.

Adding the ECB Menu Item

The solution that you create in this walkthrough creates a list item context menu entry for Microsoft Word .docx files. When users open the document context menu for a given .docx file, they can click the new entry to initiate the conversion of the document. To modify the ECB menu, you create a new feature and then add a new context menu item.

To create a feature

  1. In the Solution Explorer, right-click Features, and then click Add Feature.

  2. Type a title for the feature; for example, Convert Document.

  3. Type a description for the feature; for example, This feature converts Word Open XML documents by using Word Automation Services.

  4. Accept the Web default feature scope, which gives the SharePoint Server 2010 farm administrators the ability to enable or disable the feature on a per-site basis.

After you create the feature, add the new context menu item.

To add a context menu item

  1. In the Solution Explorer, right-click the project, point to Add, and then click New Item…

  2. In the Add New Item dialog, select Empty Element to create a blank element file in which you can add the XML code that defines the context menu item.

  3. Type a name for the element; for example ContextMenuItem.

  4. Click Add to add the element to the project. The new element appears in the Solution Explorer.

  5. In the Solution Explorer, double-click Elements.xml to open it for editing.

  6. In the XML for the Elements.xml file, add the following XML code in the <Elements> element.

    <CustomAction Id="ConvertDocument" RegistrationType="FileType" RegistrationId="docx" Location="EditControlBlock" Sequence="106" Title="Convert Document"></CustomAction>
    

    The XML code defines the new document conversion custom action by setting the following attributes:

    • Id specifies an arbitrary unique ID for this action; in this case, ConvertDocument.

    • RegistrationType specifies when this context menu item appears. In this case, you use FileType to specify that the new context menu item is associated with a specific file name extension.

    • RegistrationId specifies the file type to use for this context menu item. In this case, you use docx to limit the menu item to files that have the .docx file name extension.

    • Location specifies where to add the menu item. In this case, you use EditControlBlock to place the action on the list item context menu.

    • Sequence specifies where the item appears relative to the other items in the menu.

    • Title specifies the name of the custom menu item; for example, ConvertDocument.

  7. In the <CustomAction> element, add the following XML code.

    <UrlAction Url="~site/_layouts/ConvertItem/ConvertItem.aspx?ListId={ListId}&amp;ItemId={ItemId}&amp;ItemUrl={ItemUrl}"/>
    

    The XML code defines a URL to a SharePoint Web page that opens when the user invokes this custom action. The URL starts with ~site/, which resolves to the URL of the current SharePoint Server 2010 site. The URL also specifies three query parameters and their associated tokens:

    • {ListId}, which resolves to the ID of the parent list.

    • {ItemId}, which resolves to the ID of the list item.

    • {ItemUrl}, which resolves to the site-relative URL of the list item.

See Also

Tasks

Step 1: Set Up the Visual Studio 2010 Project for the ECB Menu Item Solution

Step 3: Create a Web Application Page to Start Conversions

Step 4: Create a Web Application Page to Monitor Conversions

Step 5: Build and Deploy the ECB Menu Solution

Concepts

Walkthrough: Use an Edit Control Block Menu Item to Create a Conversion Job