Sunday 18 September 2011

Programmatically add links to Global navigation in Sharepoint


Short code block to add links to the Global Navigation of the Top site collection

using (SPSite site = new SPSite("http://SPSitecoll"))
{
using (SPWeb web = site.OpenWeb("SubSite"))
{
if (web.IsRootWeb)
{

// Get the top link bar.
SPNavigationNodeCollection topnav = web.ParentWeb.Navigation.TopNavigationBar;

string linkTitle = web.Title; -> Adding Web's title as Link

// Create the node.
SPNavigationNode node = new SPNavigationNode(linkTitle, web.ServerRelativeUrl);

node = topnav.AddAsLast(node);
}
}
}

Ads by Google

No comments:

Post a Comment