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.

1

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

|improve this answer|||||
  • The code you wrote isnt quite what I was looking for, but the link you provided helped. – John S Mar 19 '14 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

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.