GenerateStreamFromString.cs

Method C# for convert String to Stream

/// <summary>
/// Generates a <see cref="Stream"/> from the given string.
/// </summary>
/// <param name="s">The input string.</param>
/// <returns>A <see cref="Stream"/> containing the data from the input string.</returns>
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;
}