WSS 3.0 : Adding links to the quick launch bar

Microsoft.SharePoint.Navigation API allow us to add new link to the quick launch bar of your site. The sample code in the SDK is as follows.

 

SPSite siteCollection = SPControl.GetContextSite(Context);

SPWeb site = siteCollection.AllWebs["TestSite"];

SPWeb subSite = site.Webs["SubTestSite"];

 

SPNavigationNodeCollection nodes = subSite.Navigation.QuickLaunch;

SPNavigationNode navNode = new SPNavigationNode("New Link", "http://www.msn.com", true);

nodes.AddAsFirst(navNode);

 

 

Question #1 : How can I add links to my subsites?

 

                You can add the links to your subsites for your site as below.

SPNavigationNode navNode = new SPNavigationNode("New Link", "subsite1/subsite2", true);

 

                The result will be http://<server>/sites/ TestSite/Subsite1/subsite2

 

Question #2: How can I add links to the external site?

 

SPNavigationNode navNode = new SPNavigationNode("New Link", "http://www.msn.com", true);

 

Note : Its mandatory that you have to use “http” (or any other protocol specifier) in the url parameter to specify the external url. Other wise it will be treated as a relative path. Say if you pass, “www.msn.com”, then the result will be TestSite/www.msn.com. so the protocol specifier should be used in the URL.