PS: Ok i just checked only my unicoded .txt files wont open correctly. Standard .txt files will.
| if (openFileDialog1.ShowDialog() != DialogResult.Cancel) |
| { |
| StreamReader fs =new StreamReader( new FileStream(openFileDialog1.FileName, FileMode.OpenOrCreate, FileAccess.Read)); |
| while (fs.Peek() != -1) |
| { |
| leftBox.Text += fs.ReadToEnd(); |
| } |
| fs.Close(); |
| } |
AlanPosted Jul 21, 2008, 4:58 AM
You'd expect StreamReader to automatically detect a unicode text file from the byte order marks but try specifying it explicitly in the constructor:
StreamReader fs =new StreamReader( new FileStream(openFileDialog1.FileName, FileMode.OpenOrCreate, FileAccess.Read), System.Text.Encoding.Unicode);