UrlAction Tokens in SharePoint 2010

When creating CustomAction Elements, a number of tokens are available for use within the UrlAction Element in SharePoint 2010. The list of UrlAction tokens in SharePoint 2010 has grown ever so slightly (For a SharePoint 2007 reference, see UrlAction Tokens Of The CustomAction Feature).

Tokens

Key
Available in 2007
Available in 2010
Token Replacement
~site/ SPContext.Current.Web.ServerRelativeUrl
~sitecollection/ SPContext.Current.Site.ServerRelativeUrl
{ItemId} SPListItem.ID.ToString() or SPListItem["BdcIdentity"] (external data source)
{ItemUrl} SPListItem.Url
{SiteUrl} SPWeb.Url
{ListId} SPList.ID.ToString(“B”)
{RecurrenceId} SPListItem.RecurrenceID
{ListUrlDir} SPList.RootFolder.Url
{Source} Current Request Url

Microsoft.SharePoint.SPCustomActionElement.ReplaceUrlTokens

internal static string ReplaceUrlTokens(string urlAction, SPWeb web, SPList list, SPListItem item)
{
	if (string.IsNullOrEmpty(urlAction))
	{
		return urlAction;
	}
	if (item != null)
	{
		int d = item.ID;
		string str1 = d.ToString(CultureInfo.InvariantCulture);
		if (list.HasExternalDataSource)
		{
			str1 = item["BdcIdentity"] as string;
		}
		urlAction = urlAction.Replace("{ItemId}", str1);
		urlAction = urlAction.Replace("{ItemUrl}", item.Url);
		string recurrenceID = str1;
		if (!string.IsNullOrEmpty(item.RecurrenceID))
		{
			recurrenceID = item.RecurrenceID;
		}
		urlAction = urlAction.Replace("{RecurrenceId}", recurrenceID);
	}
	if (web != null)
	{
		urlAction = urlAction.Replace("{SiteUrl}", web.Url);
	}
	if (list != null)
	{
		urlAction = "{ListId}".Replace(Guid guid = list.ID, guid.ToString("B"));
		if (list.RootFolder != null)
		{
			urlAction = urlAction.Replace("{ListUrlDir}", list.RootFolder.Url);
		}
	}
	HttpContext current = HttpContext.Current;
	if (current != null && current.Request != null)
	{
		string rawUrl = current.Request.RawUrl;
		Uri contextUri = SPAlternateUrl.ContextUri;
		if (!string.IsNullOrEmpty(rawUrl) && null != contextUri)
		{
			string str2 = null;
			if (!SPUtility.StsStartsWith(rawUrl, "/"))
			{
				str2 = string.Concat(contextUri.GetLeftPart(UriPartial.Authority), "/", rawUrl);
			}
			else
			{
				str2 = string.Concat(contextUri.GetLeftPart(UriPartial.Authority), rawUrl);
			}
			urlAction = urlAction.Replace("{Source}", SPHttpUtility.UrlKeyValueEncode(str2));
		}
	}
	urlAction = SPUtility.GetServerRelativeUrlFromPrefixedUrl(urlAction);
	return urlAction;
}

Reference

Got MSDN?

Do you have an MSDN subscription? If not, you should. The official beta of Windows 7 has been released. I suppose it’s time for some x64 Windows 7 fun. Oh, and the Server 2008 R2 beta is also up.

Performance Optimization WordPress Plugins by W3 EDGE