public static byte[] StreamToBytes(Stream stream) { List bytes = new List(); int temp = stream.ReadByte(); while (temp != -1) { bytes.Add((byte)temp); temp = stream.ReadByte(); } return bytes.ToArray(); }