Prasad Bolla's SharePoint Blog

Click Here to go through the Interesting posts within my Blog.

Click Here to go through the new posts in my blog.

Monday, November 28, 2011

Add quick launch links Programmatically in Sharepoint 2010

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.

No comments:

Post a Comment