SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to add some links to Quicklaunch bar. The link needs to have query string parameters, eg.: /sites/project/default.aspx?mode=filter

string url = "/sites/project/default.aspx?mode=filter";
string title = "Filter";

SPNavigationNodeCollection quickLaunch = web.Navigation.QuickLaunch;
SPNavigationNode newnode = new SPNavigationNode(title, url, false);
web.Navigation.QuickLaunch.AddAsLast(newnode);

Unfortunatelly, this code adds quicklaunch link without the parameter, ie.: /sites/project/default.aspx.

What is correct way to add link with params from code?

share|improve this question
up vote 3 down vote accepted

In the SPNavigationNode make the isExternal variable as true . Check this article Link

share|improve this answer
2  
Or change constructor to: new SPNavigationNode(title, url, true); Thanks! – Tschareck Mar 20 '13 at 8:32

I know this is quite old post, but setting IsExternal to true works.. but isn't the correct way of adding Query String..

Here is how you add a Query String:

string url = "/sites/project/default.aspx";
string title = "Filter";

SPNavigationNodeCollection quickLaunch = web.Navigation.QuickLaunch;
var newNode = new SPNavigationNode(title, url, false);
quickLaunch.AddAsLast(newNode);
newNode.Properties["UrlQueryString"] = "mode=filter";
newNode.Update();

Reference:

programmatically passing navigation node url with querystring

share|improve this answer
1  
Nice solution, however this works only when publishing is enabled. See : blogs.msdn.com/b/sridhara/archive/2008/07/24/… – Nils Mar 7 at 13:54

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.