1

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>");
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.

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

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;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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