Posted on:
Categories: SharePoint
Description:

When working with custom developed web templates in an on premise SharePoint environment sometimes it’s required to customize the navigation settings or add links to external resources to the navigation.

One request was for all external resource links to open in a new browser tab. When the site is non-publishing based (e.g. a Team site) the navigation settings don’t allow for the configuration of opening links in a new tab/window. As the navigation was being configured as the site was being created it made sense to:

  • Create a site scoped feature for “Navigation Configuration”
  • Add a feature receiver to the new feature
  • Staple the feature in the web template’s Onet.xml definition file

Inside the feature receiver I used the following code to add a new link (as a child link under a resource header) that opens in a new tab. 

var web = (SPWeb) properties.Feature.Parent;
//create the new QuickLaunch heading
var quicklaunchNav = web.Navigation.QuickLaunch;
var headingNode = new SPNavigationNode(“Resources”, “”, false);
//add the new navigation node as a child to the heading
var node = new SPNavigationNode(“Link Title”, “Link URL”, true);
headingNode.Children.AddAsLast(node);
//update the navigation node properties to open in a new tab 
node.Properties["Target"] = "_blank";
node.Update(); 
web.Update();

I’ve done some research to see if there’s a CSOM or REST API method of configuring the navigation node’s target but it doesn’t appear to be supported yet, hopefully in the future that will be added.