2

I have a Uri stored in a System.Uri class which contains a query string.

If I use Uri.Query the result is ?workarea=Airconaire+Ltd

What I need is to be able to extract the Uri variables so that I can Urlencode Airconaire+Ltd to get Airconaire%2bLtd? I realise that I could use regular expressions to parse this out - but is there not a more elegant way? Using System.Uri possibly?

Edit:

I've checked out the HttpUtility.ParseQuery class but it seems to decode Url encoded characters. How can I preserve all characters (theres meant to be a + in there) How can I prevent this?

m.edmondson
  • 30,382
  • 27
  • 123
  • 206
  • HttpUtility.UrlEncode? (System.Web) – The Smallest Jan 05 '11 at 10:58
  • Possible duplicate of [Get individual query parameters from Uri](http://stackoverflow.com/questions/2884551/get-individual-query-parameters-from-uri). Short answer: use [HttpUtility.ParseQueryString()](http://msdn.microsoft.com/en-us/library/ms150046.aspx). – Frédéric Hamidi Jan 05 '11 at 10:58
  • Yep - but I can't Encode the whole ?workarea=Airconaire+Ltd just the Airconaire+Ltd – m.edmondson Jan 05 '11 at 10:59
  • http://stackoverflow.com/questions/1748609/asp-net-uri-handling – Jahan Zinedine Jan 05 '11 at 11:00
  • possible duplicate of [How to parse a query string into a NameValueCollection in .NET](http://stackoverflow.com/questions/68624/how-to-parse-a-query-string-into-a-namevaluecollection-in-net) – Druid Aug 07 '12 at 10:44

0 Answers0