I have created a site programmatically and I want to configure its current (left) navigation.
My code is:
public static void SetCurrentNavigation(SPWeb currentWeb)
{
if (currentWeb != null)
{
if (currentWeb.Configuration == 2)
{
BreakInheritenceForCurrentNavigation(currentWeb);
AddQuickLaunchItem("Lists", ListNames.EventsTitle, currentWeb.Url + "/Lists/" + ListNames.Events, currentWeb);
AddQuickLaunchItem("Lists", ListNames.DiscussionTitle, currentWeb.Url + "/Lists/" + ListNames.DepartmentDiscussionUrl, currentWeb);
AddQuickLaunchItem("Lists", ListNames.DepartmentTasksTitle, currentWeb.Url + "/Lists/" + ListNames.DepartmentTasks, currentWeb);
}
currentWeb.Update();
}
}
public static void BreakInheritenceForCurrentNavigation(SPWeb currentWeb)
{
PublishingWeb pubWeb = PublishingWeb.GetPublishingWeb(currentWeb);
currentWeb.AllowUnsafeUpdates = true;
WebNavigationSettings webNavSettings = new WebNavigationSettings(currentWeb);
pubWeb.Navigation.InheritCurrent = false;
webNavSettings.CurrentNavigation.Source = StandardNavigationSource.PortalProvider;
pubWeb.Navigation.ShowSiblings = false;
DeleteRecentTag(currentWeb);
pubWeb.Update();
}
public static void DeleteRecentTag(SPWeb currWeb)
{
using (SPWeb web = currWeb)
{
web.AllowUnsafeUpdates = true;
SPNavigationNodeCollection quickLaunch = web.Navigation.QuickLaunch;
SPNavigationNode nodeHeader = quickLaunch.Cast<SPNavigationNode>().Where(n => n.Title == "Recent").FirstOrDefault();
if (nodeHeader != null)
{
quickLaunch.Delete(nodeHeader);
}
web.Update();
}
}
I debugged the whole program and its running fine but I am not getting the navigation affected i.e. the inheritance gets break but the lists are not displayed.
After site created I checked the navigation, in that I found no options are selected in current navigation and the labels and headers are added.
Preview is as below:
I found that I need to What am I missing?