Question: I know i can do this

```
var nv = HttpUtility.ParseQueryString(req.RawUrl);

```

But is there a way to convert this back to a url?

```
var newUrl = HttpUtility.Something("/page", nv);

```

Answer: 
This should work without too much code:

```
NameValueCollection nameValues = HttpUtility.ParseQueryString(String.Empty);
nameValues.Add(Request.QueryString);
// modify nameValues if desired
var newUrl = "/page?" + nameValues;

```

The idea is to use `HttpUtility.ParseQueryString` to generate an empty collection of type `HttpValueCollection`. This class is a subclass of `NameValueCollection` that is marked as `internal` so that your code cannot easily create an instance of it.

The nice thing about `HttpValueCollection` is that the `ToString` method takes care of the encoding for you. By leveraging the `NameValueCollection.Add(NameValueCollection)` method, you can add the existing query string parameters to your newly created object without having to first convert the `Request.QueryString` collection into a url-encoded string, then parsing it back into a collection.

This technique can be exposed as an extension method as well:

```
public static string ToQueryString(this NameValueCollection nameValueCollection)
{
    NameValueCollection httpValueCollection = HttpUtility.ParseQueryString(String.Empty);
    httpValueCollection.Add(nameValueCollection);
    return httpValueCollection.ToString();
}

```
I always use UriBuilder to convert an url with a querystring back to a valid and properly encoded url.

```
var url = "http://my-link.com?foo=bar";

var uriBuilder = new UriBuilder(url);
var query = HttpUtility.ParseQueryString(uriBuilder.Query);
query.Add("yep", "foo&bar");

uriBuilder.Query = query.ToString();
var result = uriBuilder.ToString();

// http://my-link.com:80/?foo=bar&yep=foo%26bar

```