WriteToFileUtf8
Write File in UTF8 from MemoryStream
Source
public static void WriteToFileUtf8(this MemoryStream stream, String path)
{
using (var writer = new FileStream(path, FileMode.Create, FileAccess.ReadWrite))
{
Encoding enc = new UTF8Encoding(false, false);
var chars = enc.GetString(stream.ToArray());
var bytes = enc.GetBytes(chars.ToCharArray());
writer.Write(bytes, 0, bytes.Length);
}
}
Example
var path = "C:\\doc.txt";
using (MemoryStream ms = new MemoryStream())
ms..WriteToFileUtf8(path);
}