1

I must be missing something but I cant find what property relates to this in the SPWeb member properties.

The property is represented by a checkbox, so I know its a boolean, and the field is described in the navigation settings page as "Add new pages to navigation automatically ".

Thanks.

2 Answers 2

0

I think this is what you are looking for:

// Web Navigation
using (var site = new SPSite("http://yoursite/"))
{
 using (var web= site.OpenWeb())
 {
    // PublishingWeb Navigation
    var pubWeb = PublishingWeb.GetPublishingWeb(web);

    // Exclude subsites to appear in navigation
    pubWeb.Navigation.CurrentIncludeSubSites = false;
    // Exclude new pages to appear in navigation
    pubWeb.Navigation.CurrentIncludePages = false;
    // Maximum number of dynamic levels
    pubWeb.Navigation.CurrentDynamicChildLimit = 20;

    pubWeb.Update();
 }
}

Reference:

Programmatically set navigation settings in SharePoint 2013

1
  • The code you wrote isnt quite what I was looking for, but the link you provided helped.
    – user5907
    Mar 19, 2014 at 17:34
0

It's using the SPWeb.Navigation.TopNavigationBar

Excerpt from MSDN:

using (SPSite site = new SPSite("http://localhost"))
            using (SPWeb web = site.OpenWeb())
            {
                if (web.Navigation.UseShared) 
                    return; 

                // Get the top link bar.
                SPNavigationNodeCollection topnav = web.Navigation.TopNavigationBar;

                // Iterate over the collection of subsites.
                foreach (SPWeb subweb in web.Webs)
                {
                    // Check for an existing link.
                    SPNavigationNode node = web.Navigation.GetNodeByUrl(subweb.ServerRelativeUrl);
                    if (node == null || node.ParentId != 1002)
                    {
                        // No link, so add one.

                        // Truncate a long title.
                        string linkTitle = subweb.Title;
                        if (linkTitle.Length > 15)
                            linkTitle = linkTitle.Substring(0, 12) + "...";

                        // Create the link.
                        node = new SPNavigationNode(linkTitle, subweb.ServerRelativeUrl);

                        // Add it to the top link bar.
                        node = topnav.AddAsLast(node);
                    }
                    subweb.Dispose();
                }

http://msdn.microsoft.com/en-us/library/office/gg277254(v=office.14).aspx

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.