TwitterLinkedInBlog

Tuesday, March 10, 2009

SP2007 - How to Programmatically Inherit Current Navigation

Scenario: Office SharePoint Server Publishing Infrastructure is activated at the SPSite level. Office SharePoint Server Publishing is NOT activated at the SPWeb level. Attempting to inherit Current Navigation from the Parent SPWeb.

using Microsoft.SharePoint.Publishing;
  …
  PublishingWeb currentPublishingWeb = PublishingWeb.GetPublishingWeb(currentWeb);
  currentPublishingWeb.InheritCurrentNavigation = true;
  currentPublishingWeb.Update();

 // Does not work because the SPWeb is NOT a PublishingWeb:
 //if (PublishingWeb.IsPublishingWeb(currentWeb))
 //{
 //    PublishingWeb currentPublishingWeb = PublishingWeb.GetPublishingWeb(currentWeb);
 //    currentPublishingWeb.InheritCurrentNavigation = true;
 //    currentPublishingWeb.Update();
 //}
 //else
 //{
 //    currentWeb.Navigation.UseShared = true;
 //    currentWeb.Update();
 //}

No comments: