Alternative for PublishingWeb.IsPublishingWeb

December 19 2012 3 comments

Just today I wondered why something was not working with a specific custom code and was able to track the problem down by debugging to using PublishingWeb.IsPublishingWeb -method to a web in another site collection with read-permissions. The error message was somewhat puzzling, something like:

0×80070002

at Microsoft.SharePoint.Library.SPRequestInternalClass.GetWebUrl(Guid gWebId, String bstrSiteUrl)…..

Then I remembered that my colleaque Tomi Tavela had resolved figuring out whether the SPWeb object is a publishing web or not in an anonymous scenario in this post Anonymous Access and Publishing Web Pages List.

So what I did following Tomi’s approach was to implement an alternative for the awkwardly behaving PublishingWeb.IsPublishingWeb -method by creating a method which checks if the site (SPWeb) has got a Pages-library.

public static bool IsPublishingWeb(SPWeb web)
{
    if (web == null || !web.Exists) return false;
    return web.Lists.TryGetList(SPUtility.GetLocalizedString
           ("$Resources:List_Pages_UrlName", "cmscore", web.Language))
           != null;
}

Popularity: 1% [?]

3 comments to “Alternative for PublishingWeb.IsPublishingWeb”

  1. Wendy says:

    It seems that Tomi’s approach saved the day, I hope you bought some cake or biscuits for Tomi as a thank you :)

  2. Juha Alhojoki says:

    Hi Wendy, glad we could help. Every day is a cake and bisquit day for Tomi ;)

  3. Oleg says:

    Publishing features can be deactivated at some point.
    But deactivation would not delete Pages library.

Leave a Reply