문제

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.
}
도움이 되었습니까?

해결책

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
}

다른 팁

You need to save this file as unicode utf-8 format to get it right.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top