Question

When I try to iterate through the GlobalNodes collection using c# it is always empty unless I the site and manipulate the navigation settings manually.

Can anyone tell me why this is and/or give an alternative?

using (var site = new SPSite(url))
{
    using (var web = site.OpenWeb)
    {
        // this is blank
        var nodes = web.Navigation.GlobalNodes[0].Children;
        //do things...
    }
}

If I then go to the site/_layouts/settings.aspx > Look and Feel > navigation and move a site around a bit in the navigation settings the list then shows up when I refresh the page.

Was it helpful?

Solution

According to the API GlobalNodes contains "the top-level navigation nodes for the current context" which includes Home, QuickLaunch and TopNavigationBar. That suggests that the code you listed is empty because the 0th index (possibly Home) is empty.

What navigation nodes are you trying to access? Perhaps it would be better to use the Home QuickLaunch or TopNavigationBar members of web.Navigation directly?

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top