SPNavigationNode issue

Published 19 December 08 12:17 PM

While working on some enhancements for the Site Configurator Feature we just released to CodePlex, I was struggling with an unexpected behavior when trying to add create SPNavigationNodes programmatically for quick launch and top navigation links. There are two constructors to select from:

public SPNavigationNode(string title, string url)
public SPNavigationNode(string title, string url, bool isExternal)

Since I needed to support both internal and external links, I chose the second one. Adding external links and links to subsites works fine, but adding links that point to the same site seems to fail. In the following example I am trying to create a duplicate of the out-of-the-box "Lists" quick launch heading.

SPNavigationNode node = new SPNavigationNode("MyInternalLink", "/_layouts/viewlsts.aspx?BaseType=0", false);
web.Navigation.QuickLaunch.AddAsLast(node);

The link will be added like this: http://_layouts/viewlsts.aspx?BaseType=0. Which obviously is invalid. So how did I come around this? Using .NET Reflector I checked the OnSubmit method of the NavNodeCreatePage class (NavNodeCreatePage is the codebehind for newnav.aspx). This is the page used when adding navigation nodes in the user interface. Interestingly I found that the "isExternal" parameter was "hardcoded" to "true". So I changed my code to:

SPNavigationNode node = new SPNavigationNode("MyInternalLink", "/_layouts/viewlsts.aspx?BaseType=0", true); web.Navigation.QuickLaunch.AddAsLast(node);

It does not make sense to me, but at least it solved the problem. If anyone can explain it, please leave a comment.

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# SharePoint Daily said on December 22, 2008 9:15 AM:

Top News Stories Create Better Workflows in SharePoint Designer (CMSWire) Yes, you can create workflows

Leave a Comment

(required) 
(optional)
(required) 

  
Enter Code Here: Required

About Frank Jusnes

Frank Jusnes - Consultant, Microsoft Consulting Services

This Blog

Syndication

Page view tracker