Alternative for PublishingWeb.IsPublishingWeb

December 19 2012 178 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% [?]

178 comments to “Alternative for PublishingWeb.IsPublishingWeb”

  1. This article will discuss lifestyle in detail. Betty Anne Waters Net Worth

  2. This article will tell you more about this Ashlyn Peaks Age

  3. This article will let you know greater approximately this Tamara Gilmer

  4. alivelymind says:

    This is the really nice post thx: Constantine Yankoglu

  5. Hatch Utah says:

    This is the really nice post thx: Kaynette Williams

  6. Kraigsimmons says:

    Thank you for sharing this valuable information: Oliver Anthony Net Worth

  7. Kentjackson says:

    Thank you for this extremely lovely post: Laura Loomer Net Worth

  8. Jameswhitney says:

    Thank you very much for this wonderful topic: Ainsley Earhardt Age

  9. Stevestrand says:

    I’m grateful that you shared this important knowledge: https://sportzpari.net/

  10. Sportzpari says:

    Thank you for the helpful post: Sahil Bloom Wife

  11. Aaron says:

    The detailed explanation of the code and scenarios where these approaches work best is highly appreciated. Concrete Flooring

  12. Stantonhoots says:

    Many thanks for providing this fantastic topic: matt kaulig wife

  13. Donsmith says:

    Thank you for sharing this valuable information: https://1daynews.com/

  14. Donsmith says:

    Thank you for sharing this valuable information: https://1daynews.com/

  15. Marieamon says:

    Thank you for sharing this valuable information: Howard Lutnick Net Worth

  16. Rozannegrant says:

    Thank you very much for this wonderful topic: Justin Tucker Net Worth

  17. I love it That’s hilarious Guys: Gwen Stefani Net Worth

  18. Very interesting and informative blog: Alicia Keys Net Worth

  19. Thank you for this incredibly informative article: Lower Middle Class

Leave a Reply