ReadToEnd
Returns a string with the content of the input stream
Source
/// <summary>
/// Reads the content of the stream
/// </summary>
/// <param name="str">Original stream</param>
/// <returns>Returns a string with the content of the input stream</returns>
public static String ReadToEnd(this Stream str)
{
try { str.Position = 0; }
catch { }
using (StreamReader sr = new StreamReader(str))
{
return sr.ReadToEnd();
}
}
Example
//This is only an example. A file could be easily read to a String by using "System.IO.File.ReadAllText"
using (System.IO.FileStream fs = new System.IO.FileStream(@"c:\test.txt", System.IO.FileMode.Open, System.IO.FileAccess.Read))
{
String StreamContent = fs.ReadToEnd();
}