Build Query String Function?

T

tsteinke

Is there a function in C# to Build a Query String for an HttpRequest?
Like from a NameValue Collection or something?
 
J

Joerg Jooss

Is there a function in C# to Build a Query String for an HttpRequest?
Like from a NameValue Collection or something?

If UTF-8 is acceptable as underlying encoding, Sytem.UriBuilder will do
just fine.

Cheers,
 
B

Bruce Barker

trival air code:

public string BuildQueryString(NameValueCollection values)
{
StringBuilder sb = new StringBuilder();
for (i =0; i < values; ++ i)
{
sb.Append(i == 0 ? "?" : "&");
sb.Append(values.Keys);
sb.Append("=");
sb.Append(HttpUtility.UrlEncode(values));
}
return sb.ToString();
}

-- bruce (sqlwork.com)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top