Archive for the ‘SP2010 UI’ Category

Quite some time ago, I noticed a significant difference between the navigation links that SharePoint adds and the ones that we add through the UI: manually created links were not security trimmed. Last August, I found and responded to a forum question on MSDN which discusses how to add navigation links to the Top Nav which do get security trimmed. I would like to elaborate on this a bit further…

Using the SharePoint 2010 Management Shell, you can add links to the navigation (Top Nav, Quick Launch, and probably any other navigation collection which uses SPNavigationNode) which do get security trimmed. To add to the Top Nav, execute the following (substituting values in the “[…]” blocks as appropriate):

$w = get-spweb [full site path]
$nav = $w.Navigation.TopNavigationBar
$newLink = new-object Microsoft.SharePoint.Navigation.SPNavigationNode -argumentlist @("[description/title]", "[web address]")

I usually like to add the link at the end of the existing list of links (hence, the use of AddAsLast), but other addition methods (namely Add and AddAsFirst) are also available. Be sure to use a relative path for the web address so the link works across web application zones with different domains. A complete example would look as follows:

$w = get-spweb http://sharepoint/site/site
$nav = $w.Navigation.TopNavigationBar
$newLink = new-object Microsoft.SharePoint.Navigation.SPNavigationNode -argumentlist @("My link", "/site/site/default.aspx")

Links can similarly be added to the Quick Launch, but with a little twist to accommodate the commonly found node nesting:

$w = get-spweb [full site path]
$nav = $w.Navigation.QuickLaunch
$navNode = ($nav | where-object { $_.Title -eq "[description/title of parent node]" })
$newLink = new-object Microsoft.SharePoint.Navigation.SPNavigationNode -argumentlist @("[description/title]", "[web address]")

In getting the parent node, I like to use the Title property, but this can be problematic if you have more than one SPNavigationNode at the root level with the same title. If need be, you can of course use other SPNavigationNode properties to filter the SPNavigationNodeCollection returned to $nav as necessary.

My thanks to Brett Pitstick who was really quite close on what he posted in the MSDN forum question he asked. Though, I still don’t know if this does the trick in Foundation. If anyone finds it does or doesn’t, please let me know.

Follow-up (2/8/2012): A user responded on a Technet SharePoint Forum thread that this does indeed work in SharePoint Foundation 2010 (SPF2010 SP1).


Read Full Post »

« Newer Posts