Geeks With Blogs
Michael Van Cleave Traveling the technical world, learning the language

So recently I have had to make the transition from the SharePoint 2007 codebase to SharePoint 2010 codebase. Needless to say there hasn't been much difficulty in the changeover.

However in a set of code that I was playing around with and transitioning I did find one change that might cause some pain to others out there that have been programming against the PublishingWeb object in the Microsoft.SharePoint.Publishing namespace.

The 2007 snippet of code that work just fine in 2007 looks like:

using (SPSite site = new SPSite(url))
using (SPWeb web = site.OpenWeb())

    PublishingWeb publishingWeb = PublishingWeb.GetPublishingWeb(web);

    publishingWeb.ExcludeFromNavigation(true, itemID);
    publishingWeb.Update();
}

The 2010 update to the code looks like:

using (SPSite site = new SPSite(url))
using (SPWeb web = site.OpenWeb())
{
    PublishingWeb publishingWeb = PublishingWeb.GetPublishingWeb(web);

    publishingWeb.Navigation.ExcludeFromNavigation(true, itemID); //--Had to reference the Navigation object.
    publishingWeb.Update();
}

The purpose of the code is to keep a page from showing up on the global or current navigation when it is added to the pages library. However you see that the update to the 2010 codebase actually makes more "object" sense. It specifies that you are technically affecting the Navigation of the Publishing Web, instead of the Publishing Web itself.

Another point that I have found interesting is that other methods or properties that essentially have been changed on the object (in this same manner) have been shown as Obsolete with a reference to the updated code expectations and will still complile, whereas this is not the case for this specific method.  It isn't a huge deal, but it kind of sucks that this is a breaking change in the codeset where the other methods and properties don't seem to be.

I know that this isn't a difficult problem to fix, but I thought it would be something quick to help out the general public.

Michael

Posted on Wednesday, April 14, 2010 10:24 AM SharePoint , General Ramblings , .NET | Back to top


Comments on this post: PublishingWeb.ExcludeFromNavigation Missing

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © Michael Van Cleave | Powered by: GeeksWithBlogs.net