2

I'm having a SharePoint site where I disabled the "show pages" option in the navigation, and created my navigation using the add static heading/link option. My problem now is that I tried to Programatically read these links, but it seems that topnav.Navigation.GlobalNodes[1].Children is returning all nodes even for those that are hidden (the hidden dynamic nodes for pages). I'm not really sure how can I omit these nodes to get only those explicitly set by the user.

My code is

 SPNavigationNodeCollection topnav = _site.Navigation.TopNavigationBar;
                foreach (SPNavigationNode node in topnav.Navigation.GlobalNodes[1].Children)
                {
                    strBuilder.Append("<li>");
                    strBuilder.Append(String.Format("<a href='{0}'>{1}</a>", node.Url, node.Title));
                    if (node.Children.Count > 0)
                    {
                        strBuilder.Append(String.Format("<ul>"));
                        foreach (SPNavigationNode childNode in node.Children)
                        {
                            strBuilder.Append(String.Format("<li><a href='{0}'>{1}</a></li>", childNode.Url, childNode.Title));
                        }
                        strBuilder.Append(String.Format("</ul>"));
                    }
                    strBuilder.Append("</li>");
                }
                strBuilder.Append("</ul>");

2 Answers 2

2

Actually I found the solution by returning only the nodes with the property bag "NodeType" not equal to "Page" by the adding the following statement in the top of my outer foreach

if ((string) node.Properties["NodeType"] == "Page") continue;
1

I had the same problem in the quick launch navigation. I solve this issue and describe solution in this thread. I think that it should work in your case, but you should use

settings.Parameters["NavigationType"] = PortalNavigationType.Global.ToString();

Also this settings does not contain all needed properties. You can open your web.config and find which properties you should add in providers section.

3
  • Thanks Alex for your answer, but I found a simpler solution for my case. Check my answer below Mar 21, 2012 at 6:40
  • I think that in your solution the hidden elements of navigation will be shown.
    – Alexander
    Mar 21, 2012 at 7:59
  • No it doesn't... you can try it Mar 22, 2012 at 19:41

Your Answer

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

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