Add quick launch links Programmatically in Sharepoint 2010

As you may know that the Navigation property of the Microsoft.SharePoint.SPWeb class gets a Microsoft.SharePoint.Navigation.SPNavigation object that contains all the navigation properties for a specified site and the QuickLaunch property of the SPNavigation object returns the collection of navigation nodes found in the Quick Launch area. The things are no different in SharePoint 2010 you can add a new link in your quick launch by adding a new SPNavigationNode type node to SPNavigationNodeCollection.

Code example :

SPSite siteCollection = SPControl.GetContextSite(Context);
SPWeb site = siteCollection.AllWebs[“MySitecoll”];
SPWeb subSite = site.Webs[“MyWeb”];

SPNavigationNodeCollection nodes = subSite.Navigation.QuickLaunch;
SPNavigationNode navNode = new SPNavigationNode(“New Link”, “/Pages/mylib/Allitems.aspx”, false);
nodes.AddAsFirst(navNode);

The third parameter of the SPNavigationNode constructor is set to true if the URL for the new link is external to the SharePoint Foundation deployment.

Also please note: You must add a Microsoft.SharePoint.WebControls.FormDigest control to the page making the post.

Related Post : Programmatically Show\Hide or Change links in quick launch bar
My old Post :

Speak Your Mind

*