I have an app that opens a text file, but i can't see the accents, instead i see something like this:
cu l es l
the problem is by reading the file or a property in the textbox where is displayed
Visual C# General
I have an app that opens a text file, but i can't see the accents, instead i see something like this:
cu l es l
the problem is by reading the file or a property in the textbox where is displayed
Open the text file with what application, yours
If it's just your application with the problem, how are you reading/writing the data in the text file
Yes the problems happens in my app, because in Notepad works perfectly.
This is the fragment of code that i use:
FileStream
fs = File.OpenRead(txtArchivo.Text); StreamReader sr = new StreamReader(fs);textBox1.Text = sr.ReadToEnd();
i've seen similar code in books but they didn't mention this could cause problems
I selected the Encoding.UTF7 and worked, but i was thinking, how would i know which encoding is used on each file that i try to open
is there a way to detect this , so then you select the appropiated encoding method
I checked what you said about BOM (byte-order-marks) and used the constructor as following:
StreamReader
(fs,true);
so it can search for the encoding, but that didn't work, then i tried this another form:
StreamReader
(fs,Encoding.Default,true)
and that works, but only because the Encoding is set to default, still works if i remove the "true" setting, so is not affecting.
i'm i using the correct way to set BOM or what i'm i doing wrong
StreamReader(fs,true) is effectively the same as StreamReader(fs, Encoding.UTF8, true).
When use use Encoding.Default it will use whatever codepage Window has loaded for your system to decide what Encoding to use.