Alternative for PublishingWeb.IsPublishingWeb

December 19 2012 23 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:


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% [?]

23 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.

  4. Great looking internet site. Presume you did a great deal of your very own coding.|

  5. I benefit from browsing your site. Thank you!

  6. Hello, very good internet site you possess in here

  7. nba 2k17 says:

    Hi, very good webpage you possess at this time there

  8. madden 17 says:

    Thanks for the purpose of delivering this sort of awesome content

  9. game news says:

    Just simply wanted to point out Now i’m glad I happened on the webpage!.

  10. PCM says:

    What if pages library deleted.?

  11. our site says:

    Hello, I just checked out your blog and I loved it.

  12. click says:

    One of the greatest writes yet!

  13. relax now says:

    Awesome! These codes are the ones I have been looking for!

  14. contact us says:

    This is amazing! Thanks so much to this article!

  15. discuss here says:

    Hi Wendy, you did a great job! continue what are you doing. Thanks

  16. oh! for me this is a good alternative in publishing a web. Keep it up

  17. playing with tuning of #PublishingWeb in #SharePoint2010. amazing what you can do with few lines of code!

  18. I updated my page layouts that I deployed as a feature, but found that I could not overwrite the Layout File. The solution was to add a new page layout and then you would have to associate the new layout with every page on your site that used it.

  19. click here says:

    It is a great alternative way.

  20. Get In Touch says:

    Thanks for sharing this article!

  21. Impressive method in resolving whether an SPWeb object a publishing web or not. Thanks for sharing this post.

  22. Karlyle says:

    Excellent alternative! Thanks for this article.

Leave a Reply