This is driving me insane. I want to read a number of text files (located outside my project directory), encoded with Windows-1252, edit them as strings, and write back to those files, again as Windows-1252. Yet Visual Studio keeps churning out UTF-8 files instead.
Here's my file reading code:
using (StreamReader sr = new StreamReader(fileName, Encoding.Default))
{
String s = sr.ReadToEnd();
return s;
}
Here is my file writing code:
File.WriteAllText(fileName, joinedFileString, Encoding.Default);
In between these two I perform various edits, including adding, removing, and grepping linebreaks, but I presumed that those would be resolved in the proper encoding by specifying the encoding in File.WriteAllText. Note that I have, in the Advanced Save Options of Visual Studio, changed the default encoding to 1252. So Encoding.Default should refer to the proper one.
Yet it keeps turning files into UTF-8! :-(