Stream - ReadToEnd

A Stream extension method that reads a stream to the end.

Try it

public static string FileName = "test.txt";

public static void Main()
{	
	SaveFile();
	
	using (StreamReader sr = File.OpenText(FileName))
	{
		// C# Extension Method: Stream - ReadToEnd
		string text = sr.BaseStream.ReadToEnd();
		
		Console.WriteLine(text);
    }
}

private static void SaveFile()
{
	var html =
    @"<!DOCTYPE html>
<html>
<body>
<h1>This is <b>bold</b> heading</h1>
<p>This is <u>underlined</u> paragraph</p>
<h2>This is <i>italic</i> heading</h2>
</body>
</html> ";
	
	html.SaveAs(FileName);
}

View Source
using System.IO;
using System.Security.Cryptography;
using System.Text;

public static partial class Extensions
{
    /// <summary>
    ///     A Stream extension method that converts the @this to a md 5 hash.
    /// </summary>
    /// <param name="this">The @this to act on.</param>
    /// <returns>@this as a string.</returns>
    public static string ToMD5Hash(this Stream @this)
    {
        using (MD5 md5 = MD5.Create())
        {
            byte[] hashBytes = md5.ComputeHash(@this);
            var sb = new StringBuilder();
            foreach (byte bytes in hashBytes)
            {
                sb.Append(bytes.ToString("X2"));
            }

            return sb.ToString();
        }
    }
}