I have a file that contains non-English chars and was saved in ANSI encoding using a non-English codepage. How can I read this file in C# and see the file content correctly?
Not working
StreamReader sr=new StreamReader(@"C:APPLICATIONS.xml",Encoding.ASCII);
var ags = sr.ReadToEnd();
sr=new StreamReader(@"C:APPLICATIONS.xml",Encoding.UTF8);
ags = sr.ReadToEnd();
sr=new StreamReader(@"C:APPLICATIONS.xml",Encoding.Unicode);
ags = sr.ReadToEnd();
Working but I need to know what is the code page in advance, which is not possible.
sr=new StreamReader(@"C:APPLICATIONS.xml",Encoding.GetEncoding(1252));
ags = sr.ReadToEnd();
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…