Monday, August 10, 2009

Code: Parse Query String Outside of a Web Page

NameValueCollection queryString = HttpUtility.ParseQueryString(myQueryString);
string myId = queryString["myid"];

There are many reasons why a person would want to parse a query string outside of a web page. In order to accomplish this in C# .Net you can use the System.Web.HttpUtility.ParseQuerystring() method. One thing to note however is that you should not pass a full URL, it expects the query string only (everything starting with the "?").

Source: MSDN