Archive for posts tagged with 'QueryString'
-
How to convert NameValueCollection to a (Query) String [Revised]
Following on from a comment on my previous post about converting a NameValueCollection to a (query) string – I have finally got around to revising my code snippet. Now the method will handle same key multiple values, (it no longer comma-separates them). I have also added extra parameters so that you can define your own delimiter (since the HTTP specification says that you can use both ampersands & and semicolons ;) and there is an…
-
How to convert NameValueCollection to a (Query) String
Most ASP.NET developers know that you can get a key/value pair string from the Request.QueryString object (via the .ToString() method). However that functionality isn't the same for a generic NameValueCollection object (of which Request.QueryString is derived from). So how do you take a NameValueCollection object and get a nicely formatted key/value pair string? (i.e. "key1=value1&key2=value2") ... Here's a method I wrote a while ago: /// <summary> /// Constructs a QueryString (string). /// Consider this method…
-
Making Request.QueryString writable (by clone/copy)
Every now and then I completely forget that the Request.QueryString (and Request.Form) object is read-only. Today I had a bit of functionality where I needed to remove a key/value from the collection - but the Remove() method (of the NameValueCollection object) throws an exception. Unfortunately, the Request.QueryString's CopyTo method assigns the values to an ARRAY, not a NameValueCollection - losing functionality and flexibility. You need to copy the Request.QueryString object to a new NameValueCollection instance,…