Create the Edit Control Block 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.
 
Here is example of Custom Action
<CustomAction
Id="MyId"
RegistrationType="ContentType"
RegistrationId="0x0101[Guid]"
Location="EditControlBlock"
ImageUrl="/_layouts/images/EDIT.GIF"
Sequence="106"
Title="Edit Procedure">
<UrlAction Url="~site/MyList/Forms/EditForm.aspx?ID={ItemId}&amp;List={ListId}"/>
</CustomAction>
 
-----------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<CustomAction  GroupId="SiteCollections" Id="PrintHelloWorld" Sequence="100" Location="Microsoft.SharePoint.Administration.Applications" Title="Print Hello World" RequiredAdmin="Delegated" >
<UrlAction Url="/_layouts/HelloWorld/hello.aspx"/>
</CustomAction>
</Elements>
 
---------------------------------------------
 <CustomAction Id="CampaignOpp.SendToAdministration"
  RegistrationType="ContentType"
  RegistrationId="0x0100474BBA4EC75C724FB75F41D8E6E4E29801"
  ImageUrl="/_layouts/images/32316.GIF"
  Location="EditControlBlock"
  Sequence="240"
  Title="Send to Administration" >
  <UrlAction Url="~site/_layouts/MyFeature/SendToAdministration.aspx?ItemId={ItemId}&amp;ListId={ListId}"/>
 </CustomAction>
 
---------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<CustomAction
Id="ECBViewNewWindow"
RegistrationType="List"
RegistrationId="107"
Location="EditControlBlock"
Sequence="199"
Title="View (new window)"
Description="Open this item in a new window (rather than a modal box)"
ImageUrl="/_layouts/images/LIST.gif">
<UrlAction
Url="javascript:window.open(‘DispForm.aspx?ID={ItemId}');"
/>
</CustomAction>
</Elements>
--------------------------------------------
 

Comments

Popular Posts

SharePoint Interview Questions and Answers

Download Infopath Form Templates

How to get current logged user information using JavaScript ?

Steps to set Form based authentication (FBA) for SharePoint 2010

SharePoint Interview Questions and Answers II

Get List Items - JavaScript

Change Language for current user with JSOM in SharePoint Online

Cross Site List Rollup Web Part for SharePoint 2010

Hide Recently Modified Items

SharePoint 2010 CSS Chart