Jun 24

One of my colleagues has been asked if it is possible to open link from the TopNavigation bar in a new window and he replied that not's easily possible by default in SharePoint. In one of my past project, I did a custom TopNavigation to display some custom ajax-flyouts. So I know that at least, we can override the rendering behavior of the bar. But without using a gun to kill a fly, we can go to Site Settings > Top Navigation > Modify a link and select "open in a new window" (only available in MOSS but WSS users… wait! The solution works too for you).

 

Did you know that you can achieve the same result programmatically with only 2 lines of code?

SPNavigationNode node = new SPNavigationNode("NotesFor .Net", http://www.notesfor.net");
topNavigationNodes.AddAsLast(node);
node.Properties["Target"] = "_blank";
node.Update();

 

Respect this order because the Properties property is null unless you add the node to a parent.

Beware this code works only if you use the Microsoft.SharePoint.WebControls.AspMenu (<SharePoint:AspMenu> or a class inheriting from) in your masterpage. Not the default <asp:Menu>.
This works both in WSS and MOSS Cool

 

For the curious readers, the explanation is simple. Looking at the code of AspMenu with Reflector, we see that the mapping is done automatically by SharePoint:

Tags:
Comments are closed