Wednesday, November 25, 2009

Global navigation problem with minimal publishing site definition

For all of us the WCM book by Andrew Connell is the how-to guide for developing publishing sites with MOSS. Connell suggests going for a minimal publishing site definition instead of the default OOB site definition from MS. The minimal site definition available as a download is great but there is but one small problem with that the navigation node - see it here

-------------------------------------
Page 81, Listing 5-6: The element is not syntactically correct... looks like some stuff was trimmed out by mistake. Replace the line that looks like this:
NavBars>
<NavBar Name="SharePoint Top Navbar" ID="1002" />
</NavBars>

With this:

<navbars></navbars>
<navbar name="SharePoint Top Navbar" id="1002"></navbar></navbars>
-------------------------------------

This small mistake creates quite a few problems if sites are already created from this site definition and you are not gung-ho about recreating the sites. The major problem is that any navigation setting (sorting, hiding) on global navigation will not get persisted.

You can get past some of the problems with programmatically modifying the global navigation in case you get in to this situation

Let us say you want to hide site from global navigation, here is what you have to do

string siteURL = <>;
SPSecurity.RunWithElevatedPrivileges(delegate() {
SPSite site = new SPSite(siteURL);
SPWeb web = site.OpenWeb();
if (PublishingWeb.IsPublishingWeb(web))
{
PublishingWeb publish = PublishingWeb.GetPublishingWeb(web);
Console.WriteLine("Site is " + publish.Title.ToString());
Console.WriteLine("Global Navigation current setting:" + publish.IncludeInGlobalNavigation);
publish.IncludeInGlobalNavigation = false;
Console.WriteLine("Global Navigation changed setting:" + publish.IncludeInGlobalNavigation);
publish.Update();
}
});

of course, dont forget to dispose of your SPWeb and SPSite at the end;

No comments: