Arshad Mehmood

Search the blog

    Create a stream from string

    csharp1 min read

    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