Unicode problem File.WriteAllText

I have raw data (xml) that I definitely get containing unicode. I write them to a file using:

File.WriteAllText 

This seems to remove / change Unicode characters. Is there any way to prevent this?

Thanks.

Christian

+4
source share
4 answers

Try File.WriteAllText overload, which allows you to specify the encoding - just give it the same encoding of the source data.

+5
source

You can specify the encoding:

 File.WriteAllText(fileName, xml, Encoding.Unicode); 
+6
source

you can specify the Encoding as parameter for the WriteAllText function, see the available overloads :)

+2
source

Use the correct encoding, which is the third parameter.

 File.WriteAllText(file, contents, encoding); 
+1
source

All Articles