SharePoint Internals – Hristo Pavlov’s Blog

8 December, 2008

UrlAction Tokens of the CustomAction Feature

Filed under: SharePoint — Tags: , , , , , , , , , — hristopavlov @ 1:07 am

I was looking today for the complete list of tokens that can be used in the UrlAction element when building a CustomAction feature but I couldn’t find much. So I decided to put together this blog entry to help other people that may be looking for the same thing.

As you know some tokens can be used when specifying the Url of the custom action: 


Those token will be replaced by SharePoint at runtime with values derived from the current context. To get the complete list we just need to find the function that does the replacement. Luckily this function is in the .NET libraries of SharePoint and can be disassembled with Reflector. So here is the complete list of the tokens:

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(“B”)
{RecurrenceId} item.RecurrenceID

For the records the method that does the replacement is Microsoft.SharePoint.SPCustomActionElement.ReplaceUrlTokens() and looks like this:

private static string ReplaceUrlTokens(

    string urlAction,

    SPWeb web,

    SPList list,

    SPListItem item)


    string recurrenceID;


    if (!string.IsNullOrEmpty(urlAction))


        if (item != null)


            string newValue = item.ID.ToString(CultureInfo.InvariantCulture);


            urlAction = urlAction.Replace(“{ItemId}”, newValue);

            urlAction = urlAction.Replace(“{ItemUrl}”, item.Url);

            recurrenceID = newValue;


            if (!string.IsNullOrEmpty(item.RecurrenceID))


                recurrenceID = item.RecurrenceID;






        return urlAction;



    urlAction = urlAction.Replace(“{RecurrenceId}”, recurrenceID);


    if (web != null)

        urlAction = urlAction.Replace(“{SiteUrl}”, web.Url);


    if (list != null)

        urlAction = urlAction.Replace(“{ListId}”, list.ID.ToString(“B”));


    // Replaces ~site/ and ~sitecollection/ with the site and site collection urls

    urlAction = SPUtility.GetServerRelativeUrlFromPrefixedUrl(urlAction);


    return urlAction;


The web, list and item arguments are taken from the context before the user is redirected to the custom action page.

Blog at