less than 1 minute read

Create a stream from string

Use this function:

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 close the stream after using it.

Got it from here

Leave a comment