Welcome to MSDN Blogs Sign in | Join | Help
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!

Posted: Saturday, May 17, 2008 4:24 PM by itsmeskv

Comments

Christoph Herold said:

Hi!

Do you have any idea, how to set the order of the websites/pages when you set the sorting to manual? I have not been able to find a way to do this in a publishing site, since the SPNavigationNode.Move()-methods don't seem to work. Any help would be great!

Cheers

Christoph

# June 2, 2008 5:14 AM
Leave a Comment

(required) 

(required) 

(optional)

(required) 

  
Enter Code Here: Required

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Page view tracker