Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I found some code on net for Update quick launch like which allow to add and might be update quick launch link


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);


But my question is how to hook the code to a SharePoint site such that it gets executed every time on user login to site. Can you please provide any inputs on that?
Posted

1 solution

It is sometimes dangerous to just use code without understanding it. The objects here are not being properly disposed of nor used correctly.

If you need the QuickLaunch to be modified for each user it would be easier, and perhaps more reliable and robust to create your own navigation control. The existing QuickLaunch menu is an ASP.NET menu control that uses a SiteMapDataSource. Very easy to derive your own, use the same data source and add the items as necessary for each user.
 
Share this answer
 
Comments
Khaniya 28-Jun-11 8:18am    
yes I agree
but my question is not specific to quick lunch navigation.
As I am newbie with SP, I do not know how to bind code with sharepoint site.
I look around event receiver, but don't find anything which allow me to write code on page load
[no name] 28-Jun-11 9:24am    
Unless you are creating an application page there is no PageLoad event to hook into with SharePoint. I understand you are a newbie but you should look into how SharePoint renders pages to understand what is happening before diving in. Look up Virtual Path provider. SharePoint specifically restricts code in some pages and uses templates so code added to one would effect all pages, not really what you want to happen. WebParts or server controls are more widely used to provide individual functionality on pages.

You are a newbie but SharePoint is a very large framework that can be dangerous if you don't take the time to learn it properly before trying to jump in. Take the time. It will be worth it for your career and understanding of the toolset.
Khaniya 28-Jun-11 23:53pm    
Thanks Mark for your valuable comments

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900