Friday, July 29, 2011

Getting the Welcome Page for a SharePoint Publishing Site

I wish I had found this sooner, it could have saved me a lot of time:

private static bool IsWelcomePage(string url)
{
bool rslt = false;

using (SPSite site = new SPSite(url))
{
using (SPWeb web = site.OpenWeb())
{
if (PublishingWeb.IsPublishingWeb(web))
{
PublishingWeb pweb = PublishingWeb.GetPublishingWeb(web);
string defaulturl = pweb.DefaultPage.Url;

if (defaulturl == new Uri(url).GetComponents(UriComponents.Path, UriFormat.SafeUnescaped))
{
rslt = true;
}
}
}
}

return rslt;
}

No comments: