System.IO.Stream to string

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Paul

    #1

    System.IO.Stream to string

    How do I convert a System.IO.Strea m to a string variable.

    Regards Paul
  • Jon Skeet [C# MVP]

    #2
    Re: System.IO.Strea m to string

    Paul <Paul@discussio ns.microsoft.co m> wrote:[color=blue]
    > How do I convert a System.IO.Strea m to a string variable.[/color]

    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(st ream))
    {
    string contents = reader.ReadToEn d();
    }

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

    --
    Jon Skeet - <skeet@pobox.co m>
    http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
    If replying to the group, please do not mail me too

    Comment

    Working...