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

*

Disclaimer: The contents of this site are provided “AS IS”. Information and views expressed including URL(s) and other Internet website references, may change without notice. You bear the risk of using it. SharePoint, MOSS, SharePoint 2010, SharePoint 2013 and Microsoft are trademarks of the Microsoft Corporation.Learning SharePoint only provides Tips,Tricks and Tutorials for using Microsoft SharePoint, Microsoft Office and related Softwares.
Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.