Posted by Scott on September 2, 2011
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 |
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
Posted by Scott on July 18, 2011
I recently ran into a strange error when attempting to use site templates (e.g. Save site as template) that had a “Site Pages” libary list view web part on the home page (e.g. Home.aspx). Any site created from these templates would have a corrupt home page.
The Error
The following is the home page of a site created from a template with a “Site Pages” list view web part on the home page.

The ULS error:
System.InvalidOperationException: Operation is not valid due to the current state of the object.
at Microsoft.SharePoint.SPListItem.get_EffectiveBasePermissions()
at Microsoft.SharePoint.WebPartPages.WikiEditPage.OnPreRender(EventArgs e)
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
The “Site Pages” library (note that Home.aspx is not present/visible):

The Fix
The fix is more a work-around. Do not put a “Site Pages” list view web part on the home page of any site you want to use as a template.

Posted by Scott on July 1, 2011
Posted by Scott on June 19, 2011