Setting Navigation properties on a SharePoint (WSS) Site…
Recently, I was going through setting up some sample navigation approaches for SharePoint. The first step was in creating a bunch of Child Sites and some basic hierarchical structure. For that I used a great tool from IDevFactory called SWAT just to create some empty Team Sites.
The one issue with that tool is it doesn’t allow setting a few options globally.
What I wanted was to have under the Navigation options to have the “Show Subsites” enabled. In addition to a few other navigation settings. Just as shown below:
To do that you need to access the AllProperties collection on the SPWeb object and add or update any existing entries. What I came up with is the following:
private static void SetNavigation(SPWeb childWeb)
{
if (childWeb.IsRootWeb == false)
{
SPNavigation spNav = childWeb.Navigation;
childWeb.Navigation.UseShared = true;
childWeb.Description = childWeb.Name + " description...";
SetAllPropr(childWeb, "__IncludeSubSitesInNavigation", "True");
SetAllPropr(childWeb, "__InheritCurrentNavigation", "False");
SetAllPropr(childWeb, "__IncludePagesInNavigation", "False");
SetAllPropr(childWeb, "__NavigationShowSiblings", "False");
SetAllPropr(childWeb, "__NavigationOrderingMethod", "2");
}
}
static void SetAllPropr(SPWeb web, string key, object value)
{
if (web.AllProperties.Contains(key))
web.AllProperties.Remove(key);
web.AllProperties.Add(key, value);
}
The full standalone console project is located here