PublishingWeb.ExcludeFromNavigation Missing
- by Michael Van Cleave
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.
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