I\'m looking for the simplest way of converting a query string from an HTTP GET request into a Dictionary, and back again.
I figure it\'s easier to carry out various
Same as Sean, but with Linq (and a function you can copy and paste):
public static Dictionary ParseQueryString(string queryString)
{
var nvc = HttpUtility.ParseQueryString(queryString);
return nvc.AllKeys.ToDictionary(k => k, k => nvc[k]);
}
Also, the question asked how to get it back into a query string:
public static string CreateQueryString(Dictionary parameters)
{
return string.Join("&", parameters.Select(kvp =>
string.Format("{0}={1}", kvp.Key, HttpUtility.UrlEncode(kvp.Value))));
}