I have a Stream in which there is uploaded text file. The file can have any encoding - ANSI, UTF8 without BOM, UTF8 with BOM. The file has characters which are specific for some languages - e.g. ąę. I need to save all files as UTF8 BOM files on the server side, but I can't force all users to upload me UTF8 BOM files. Special characters in saved file must maintain correct - so ąę. How can I do this?
I have:
using (Stream inputStream = file.InputStream)
{
byte[] bytes = ReadFully2(inputStream);
string utf8string = .....what here?.....
System.IO.File.WriteAllText("", utf8string, System.Text.Encoding.UTF8);
}
public static byte[] ReadFully2(Stream input)
{
input.Position = 0;
using (MemoryStream ms = new MemoryStream())
{
input.CopyTo(ms);
return ms.ToArray();
}
}