Reading HTML file into textbox translates apostrophes and bullets into?
I am using a StreamReader (in C#) to read contents of an HTML file into a textbox. No matter which encoding I use as an uption, all of the apostrophes and bullets get changed into question marks.
Is there another way to read an HTML file that will preserve these characters?
Thanks! Jerry
Here is the code:
private void button1_Click(object sender, EventArgs e)
{
DialogResult result = openFileDialog1.ShowDialog();
if (result == DialogResult.Cancel)
return;
StreamReader sr = new StreamReader(openFileDialog1.FileName);
txtMessage.Text = sr.ReadToEnd();
sr.Close();
}
I have also used the StreamReader with the Encoding parameter (tried every one). The only thing it seems to do is interpret the question marks are regular or reversed (black diamond with white question mark).
If it makes any difference, the files are created in Word by another department and then exported to Filtered HTML.
One last thing: If I open the HTML file in something like Notepad and copy/paste the text into the textbox,开发者_如何学Go then everything looks exactly as it should.
The changes only occur if I try to pull the file in via a reader.
I would try it with new StreamReader(..., Encoding.UTF8);
or new StreamReader(..., Encoding.GetEncoding("iso-8859-1"));
and if that doesn't work, then I'd go after the person who created the file and stuff needles under their fingernails until they confess what encoding they used to create it.
精彩评论