Site Navigation Settings

If you want to set Site Navigation Settings using API here is code :)

Use this to specify the navigation items that you want to display in the navigation link bars of this site. Items in sublevels and flyouts can be modified only in the navigation of the subsite that contains these items.  

This code helps you to set

  • Subsites and Pages 
  • Sorting
  • Global Navigation 
  • Current Navigation 

private AutomaticSortingMethod GetAutomaticSortingMethodFromUI()
{
    return (AutomaticSortingMethod) Enum.Parse(typeof(AutomaticSortingMethod), this.automaticSortingMethodDropDown.SelectedValue);
}

private OrderingMethod GetOrderingMethodFromUI()
{
    if (this.automaticSortingRadioButton.Checked)
    {
        return OrderingMethod.Automatic;
    }
    if (this.automaticPageSortingCheckBox.Checked)
    {
        return OrderingMethod.ManualWithAutomaticPageSorting;
    }
    return OrderingMethod.Manual;
}

public SetDisplaySettings()
{
    SPContext context = SPContext.GetContext(HttpContext.Current);
    PublishingWeb publishingWeb = PublishingWeb.GetPublishingWeb(context.Site.OpenWeb(context.Web.ServerRelativeUrl));
    publishingWeb.IncludeSubSitesInNavigation = this.showSubSitesCheckBox.Checked;
    publishingWeb.IncludePagesInNavigation = this.showPagesCheckBox.Checked;
    publishingWeb.NavigationOrderingMethod = this.GetOrderingMethodFromUI();
    if (publishingWeb.NavigationOrderingMethod != OrderingMethod.Manual)
    {
        publishingWeb.NavigationAutomaticSortingMethod = this.GetAutomaticSortingMethodFromUI();
        publishingWeb.NavigationSortAscending = this.ascendingRadioButton.Checked;
    }
    publishingWeb.InheritGlobalNavigation = this.inheritTopNavRadioButton.Checked;
    publishingWeb.InheritCurrentNavigation = this.inheritLeftNavRadioButton.Checked;
    publishingWeb.NavigationShowSiblings = this.showSiblingsLeftNavRadioButton.Checked;
    publishingWeb.Web.Update(); 
}

Enjoy code!