How do I generate a stream from a string?
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