Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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.

share|improve this question
add comment

1 Answer 1

up vote 2 down vote accepted

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?

share|improve this answer
    
TopNavigationBar is also empty until you make a change to the default navigation properties (changing the order is enough to fill the node collections) –  Mauro Aug 14 '12 at 14:19
    
Looking at the API a bit more msdn.microsoft.com/en-us/library/gg277254.aspx "If UseShared returns false, the website has its own top link bar and you can add to it. If the property returns true, the website is using its parent site's top link bar." by modifying it I guess it sets useShared to false. –  Mauro Aug 14 '12 at 14:22
    
Sorry, I think I misunderstood your question. The UseShared property and your guess sounds feasible though. –  SPDuFeu Aug 14 '12 at 14:44
    
+1 though for helping me find a solution though. –  Mauro Aug 14 '12 at 15:14
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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