System.IO.Stream to string

  • Thread starter Thread starter Guest
  • Start date Start date
Paul said:
How do I convert a System.IO.Stream to a string variable.

Do you mean you want to read the contents of a stream, decoding it into
a string, and storing the result in a variable? If so:

using (StreamReader reader = new StreamReader(stream))
{
string contents = reader.ReadToEnd();
}

Note that the above assumes an encoding of UTF-8. If you want a
different encoding, specify it in the StreamReader constructor.
 
Back
Top