Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

unicode problem File.WriteAllText

Tags:

c#

I have some raw data (xml) which I definitely receive containing unicode. I write them to a file using:

File.WriteAllText

This seems to remove/change unicode characters. Is there a way to prevent this?

like image 917
cs0815 Avatar asked Aug 05 '11 15:08

cs0815


3 Answers

You can specify the encoding:

File.WriteAllText(fileName, xml, Encoding.Unicode);
like image 129
Mark Cidade Avatar answered Nov 08 '22 23:11

Mark Cidade


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

like image 6
Justin Avatar answered Nov 08 '22 23:11

Justin


Use the proper encoding, which is the 3rd parameter.

File.WriteAllText(file, contents, encoding);
like image 2
LarsTech Avatar answered Nov 08 '22 23:11

LarsTech