Reputation: 17388
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?
Upvotes: 9
Views: 14172
Reputation: 99957
You can specify the encoding:
File.WriteAllText(fileName, xml, Encoding.Unicode);
Upvotes: 15
Reputation: 86729
Try the File.WriteAllText overload which allows you to specify an encoding - just give it the same encoding of the original data.
Upvotes: 6
Reputation: 44605
you can specify the Encoding as parameter for the WriteAllText function, see the available overloads :)
Upvotes: 2
Reputation: 81610
Use the proper encoding, which is the 3rd parameter.
File.WriteAllText(file, contents, encoding);
Upvotes: 2