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: 
Because a `NameValueCollection` can have multiple values for the same key, if you are concerned with the format of the querystring (since it will be returned as comma-separated values rather than "array notation") you may consider the following.

Example
-------

```
var nvc = new NameValueCollection();
nvc.Add("key1", "val1");
nvc.Add("key2", "val2");
nvc.Add("empty", null);
nvc.Add("key2", "val2b");

```

Turn into: `key1=val1&key2[]=val2&empty&key2[]=val2b` rather than `key1=val1&key2=val2,val2b&empty`.

Code
----

```
string qs = string.Join("&", 
    // "loop" the keys
    nvc.AllKeys.SelectMany(k => {
        // "loop" the values
        var values = nvc.GetValues(k);
        if(values == null) return new[]{ k };
        return nvc.GetValues(k).Select( (v,i) => 
            // 'gracefully' handle formatting
            // when there's 1 or more values
            string.Format(
                values.Length > 1
                    // pick your array format: k[i]=v or k[]=v, etc
                    ? "{0}[]={1}"
                    : "{0}={1}"
                , k, HttpUtility.UrlEncode(v), i)
        );
    })
);

```

or if you don't like Linq so much...

```
string qs = nvc.ToQueryString(); // using...

public static class UrlExtensions {
    public static string ToQueryString(this NameValueCollection nvc) {
        return string.Join("&", nvc.GetUrlList());
    }

    public static IEnumerable<string> GetUrlList(this NameValueCollection nvc) {
        foreach(var k in nvc.AllKeys) {
            var values = nvc.GetValues(k);
            if(values == null)  { yield return k; continue; }
            for(int i = 0; i < values.Length; i++) {
                yield return
                // 'gracefully' handle formatting
                // when there's 1 or more values
                string.Format(
                    values.Length > 1
                        // pick your array format: k[i]=v or k[]=v, etc
                        ? "{0}[]={1}"
                        : "{0}={1}"
                    , k, HttpUtility.UrlEncode(values[i]), i);
            }
        }
    }
}

```

As has been pointed out in comments already, with the exception of [this answer](https://stackoverflow.com/a/19617268/1037948) most of the other answers address the scenario (`Request.QueryString` is an `HttpValueCollection`, "not" a `NameValueCollection`) rather than the literal question.

*Update:* addressed null value issue from comment.
As @Atchitutchuk suggested, you can use QueryHelpers.AddQueryString in ASP.NET Core:

```
    public string FormatParameters(NameValueCollection parameters)
    {
        var queryString = "";
        foreach (var key in parameters.AllKeys)
        {
            foreach (var value in parameters.GetValues(key))
            {
                queryString = QueryHelpers.AddQueryString(queryString, key, value);
            }
        };

        return queryString.TrimStart('?');
    }

```