Build Query String Function?

  • Thread starter Thread starter tsteinke
  • Start date Start date
T

tsteinke

Is there a function in C# to Build a Query String for an HttpRequest?
Like from a NameValue Collection or something?
 
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,
 
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

Back
Top