I would like to add a quick link to my SharePoint Foundation 2010 site through code (like in a custom web part). If I do it through the UI, I can successfully add a quick link that points to whatever I want (e.g. www.google.com) without any issues. I go to the page, click on the link, and it takes me to Google, no problems. If I add the same quick link through code (don't ask why I need to do it like that, just assume I do), I get the following error when I navigate to the page:
<nativehr>0x81070215</nativehr><nativestack></nativestack>Cannot open "/clients/www.google.com": no such file or folder.
Here is the code I'm using to create the navigation item:
SPWeb masterweb = SPContext.Current.Site.OpenWeb("clients"); masterweb.AllowUnsafeUpdates = true; string url = "www.google.com"; string title = "Google"; SPNavigationNodeCollection quickLaunch = masterweb.Navigation.QuickLaunch; SPNavigationNode newnode = new SPNavigationNode(title, url, false); masterweb.Navigation.QuickLaunch.AddAsLast(newnode); masterweb.AllowUnsafeUpdates = false;
Is there a different way to add a Quick Launch link that I'm missing, or is there a property I'm overlooking or....?
Back Story: I have a site that contains a library of identical subsites. On the main site, I have pages that contain a library of custom web parts that pull information based on the site that has been selected (through the QueryString value). In launching those pages, I need links on the Quick Link bar that point to those pages with the Query String in tact. So, I want to basically build the Quick Link bar on the fly. So that, whatever site name is selected in the Query String, I need to append that back to the URL specified for the Quick Link. The purpose of all of this is to create a central "portal page" that can be altered at any time rather than have a million iterations of the same thing for each individual subsite (of which there are around 280).