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

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>");
share|improve this question
add comment

2 Answers

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.

share|improve this answer
    
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
add comment
up vote 1 down vote accepted

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;
share|improve this answer
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.