I am accessing the quick launch nodes programmatically by using

SPWeb currWeb = SPContext.Current.Web;
SPNavigationNodeCollection nodes = currWeb.Navigation.QuickLaunch;
foreach (SPNavigationNode node in nodes)

Strange thing is that there are more nodes in the collection than i see in SharePoint in the quick launch! The extra nodes that are in the collection are the different sub webs.

But i only want to use the "real" elements that are in the quick launch. How can i access them?

It is since i turned on the publishing features i have this issue. And using

if (PublishingWeb.IsPublishingWeb(currWeb)) { 
   PublishingWeb pubWeb = PublishingWeb.GetPublishingWeb(currWeb); 
   nodes = pubWeb.Navigation.CurrentNavigationNodes; 

to get the nodes gives the same results.


2 Answers 2

if ( (node.Properties["NodeType"] != null && node.Properties["NodeType"].ToString() =="Area" && pubWeb.Navigation.GlobalIncludeSubSites)
  || (node.Properties["NodeType"] != null && node.Properties["NodeType"].ToString() == "Page" && pubWeb.Navigation.GlobalIncludePages) 
  || (node.Properties["NodeType"] == null))
{ //display here }

Try the above logic on whether or not to hide the navigation node. Substitute Global with Current. I fixed mine for the Global navigation.

Here is a link to more information about the property http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.publishing.nodetypes(v=office.14).aspx


I believe this is normal behavior to facilitate the "display subsites" option in the navigation. You'll likely need to do some additional logic on each node to determine if it's a subweb or not and display accordingly.

  • But if i do that, it will also filter the subwebs that are manually added to the quick launch. I only want those 'hidden' items filtered.
    – Davy
    Jan 28, 2013 at 16:29

Your Answer

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

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