Adding querystring parameters to a SPNavigationNode

I've had a hard time figuring out how to programatically add or edit Querystring parameters to a SPNavigationNode. The SPNavigationNode is the internal type used to build the current (left) and global (top) WSS navigation.

It seems pretty straight forward to pass the full url to the new SPNavigationNode constructor, but the querystring part gets removed by the SharePoint API.

It turns out the Querystring part is saved in a separated propertybag.

This examples retrieves an existing link and adds a Querysstring:

SPNavigationNodeCollection nodes = PublishingWeb.GetPublishingWeb(spweb).CurrentNavigationNodes;
node = nodes[4];

// Remove the UrlQueryString property because updates are not persisted 
if (node.Properties.ContainsKey("UrlQueryString"))
    node.Properties.Remove("UrlQueryString");

node.Properties.Add("UrlQueryString", "param1=foo&param2=foo");
node.Update();

Note that you should not add the "?" at the beginning of the Querystring.

Leave a Reply