I have a question about Chinese encoding and saving back to a file. I am currently using the HtmlAgilityPack to parse HTML, do some things with it and save it back to the file. I am having a problem with Encoding, such as Chinese (GB2312 (Simplified)). When i open the file, I read the encoding and I save it back, using the HtmlAgilityPack
doc.Save(this._filePath, reader.CurrentEncoding);
but the Chinese letters get completely mutilated. Any ideas on how I can save back to the same file and maintain the current encoding? I also tried getting the Encoding with the HtmlAgilityPack like such:
FileStream fs = new FileStream(this._filePath, FileMode.Open);
StreamReader reader = new StreamReader(fs);
HtmlDocument doc = new HtmlDocument();
doc.Load(reader);
Encoding enc = doc.DeclaredEncoding;
fs.Close();
doc.Save(this._filePath, enc);
but that didn't work either. Any ideas?