1

System.Net.Mailを使用していて、電子メールの本文にhtmlを読み込んでいます。

残念ながら、アポストロフィ文字'は背景が黒の疑問符として表示されます。

アポストロフィをhtmlに置き換えようとしました'が、それでも疑問符が黒の背景で表示されます。他のHtmlタグ(h1、pなど)は正常に機能しています。

私は今、本当に明白な答えがあるに違いありませんが、私はそれを見つけることができないようです。ご協力いただきありがとうございます。

アップデート

問題を引き起こしているのはSystem.IO.StreamReaderのようです。

using (StreamReader reader = new StreamReader("/Email/Welcome.htm"))
{
     body = reader.ReadToEnd(); 
     //body string now has odd question mark character instead of apostrophe.
}
4

2 に答える 2

2

ファイルのエンコーディングがわかっている場合は、それをStreamReader初期化に渡します。

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
}
于 2012-09-20T04:06:12.047 に答える
0

正しくするには、このファイルをUnicodeutf-8形式で保存する必要があります。

于 2012-09-19T08:56:40.933 に答える