Reading a String from a Stream


Problem: You need to read some text from a stream of some sort.

Solution: Use StreamReader class , set the postion to 0 and call ReadToEnd().



static string GetStringFromStream(Stream inputStream)
var pos = inputStream.Position;
var reader = new StreamReader(inputStream);
inputStream.Position = 0;
var text = reader.ReadToEnd();
inputStream.Position = pos;
return text;