tags:

views:

1094

answers:

3

I have a site as follows:

--SiteA
----Subsite1
----Subsite2

Now whenever i try to access the QuickLaunch Property its always empty e.g

SPNavigation nav = spWeb.Navigation;
if (nav.QuickLaunch.Count == 0)
{
      // ALWAYS TRUE
}

However if i go into the Naviation Settings (Through the UI) of SiteA and reorder any site in the list, only then will the QuickLanuch become available. (Other settings are left as default)

Can anyone explain this behaviour? I really need access to the QuickLaunch items.

Thanks

A: 

I seem to remember reading somewhere that the QuickLaunch collection only stored customisations to the default ordering. Looking around, I can't find that documentation to show you, but it would explain the behaviour you see if true.

So your QuickLaunch.Count == 0 is just confirming that default ordering of items is in place.

You can still add nodes, if that's at all helpful;

SPNavigationNodeCollection nodes = web.Navigation.QuickLaunch; SPNavigationNode node = new SPNavigationNode("Node Name", "Node URL", true); nodes.AddAsFirst(node);

Jamie McAllister
A: 

I think, by default, the QuickLaunch uses shared navigation. In other words, the QuickLaunch for a subsite doesn't have its own collection of nodes until you do something with it. If you reorder a site, that gives it its own unique set of nodes.

If you wanted to programmatically set your QuickLaunch to have its own set of nodes programmatically, you should be able to do so this way:

SPNavigation nav = spWeb.Navigation;  
nav.UseShared = false;  
spWeb.Update();

I think your count should be something other than zero at that point.

Abs
A: 

Thanks. Originally i wanted to use the QuickLauch as a method to re-order subsites. Is there a way to re-order my subsites (which will ultimately appear as menu items on the public site)?