Reputation: 3699
I am using System.Net.Mail and I am reading html into the body of email.
Unfortunately the apostrophe character '
is shown as a question mark with a black background.
I have tried to replace the apostrophe with the html '
but this still displays the question mark with a black background. Other Html tags (h1, p etc) are working fine.
I now there must be a really obvious answer but I cannot seem to find it. Thanks for your help.
UPDATE
It appears that it is System.IO.StreamReader that is causing my problem.
using (StreamReader reader = new StreamReader("/Email/Welcome.htm"))
{
body = reader.ReadToEnd();
//body string now has odd question mark character instead of apostrophe.
}
Upvotes: 1
Views: 2477
Reputation: 160025
If you know the encoding of your file you will want to pass that to your StreamReader
initialization:
using (StreamReader reader = new StreamReader("/Email/Welcome.htm", "Windows-1252"))
{
body = reader.ReadToEnd();
// If the encoding is correct you'll now see ´ rather than �
// Which, by the way is the unicode replacement character
// See: http://www.fileformat.info/info/unicode/char/fffd/index.htm
}
Upvotes: 2
Reputation: 10619
You need to save this file as unicode utf-8 format to get it right.
Upvotes: 0