Thursday 17 May 2012

How to get item id and list id in CustomAction


A very nice and useful tip is what I am going to share today. If you creating a CustomAction for ECB or EditControlBlock menu most probbaly you would need to get List id and Item id in your CustomAction.
Here is the list of Tokens or paramenters available that you can use. these when used in CustomAction Url are replaced on runtime.

Token                 Replaced By
~site/                  SPContext.Current.Web.ServerRelativeUrl
~sitecollection/  SPContext.Current.Site.ServerRelativeUrl
{ItemId}            item.ID.ToString()
{ItemUrl}          item.Url
{SiteUrl}           web.Url
{ListId}             list.ID.ToString()
{RecurrenceId} item.RecurrenceID

and this is how you use it

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <CustomAction Id="{someId}"
  RegistrationType="List"
  RegistrationId= "{someId}"
  Location="EditControlBlock"
  ImageUrl="/_layouts/IMAGES/DOCLINK.GIF"
  Sequence="1001"
  Title="Click Me!"
  Description="Shows an alert message for this content type."
  >
  <UrlActionUrl="~site/_layouts/CustomPage.aspx?ID={ItemId}&amp;List={ListId}"/>
  </CustomAction>
</Elements>
 


Ads by Google

No comments:

Post a Comment