How do I convert struct System.Byte byte[] to a System.IO.Stream object in C#?
The easiest way to convert a byte array to a stream is using the MemoryStream class: Stream stream = new MemoryStream(byteArray);
The easiest way to convert a byte array to a stream is using the MemoryStream class: Stream stream = new MemoryStream(byteArray);
public static Stream GenerateStreamFromString(string s) { var stream = new MemoryStream(); var writer = new StreamWriter(stream); writer.Write(s); writer.Flush(); stream.Position = 0; return stream; } Don’t forget to use Using: using (var stream = GenerateStreamFromString(“a,b \n c,d”)) { // … Do stuff to stream } About the StreamWriter not being disposed. StreamWriter is just a wrapper … Read more