I have a c# app which is supposed to display email. the email may be HTML or plain text but i am using web browser control in both cases. the problem is web browser control is ignoring all the escape characters of plain text and the mail appear as a single line.
the work around i am using is to replace escape character "\n" or "\r" to <br>. is there any other good way to do this.
thanks in advance.
You can surround the text with <pre> and </pre> (stands for "preformatted") tag. See here: HTML pre Tag
I think, the only way is the replacing "\r\n" for <br/>.
Use the StringBuilder class for it.
var htmlText = new StringBuilder(text);
htmlText.Replace("\r\n", "\n")
.Replace("\r", "\n")
.Replace("\n", "<br/>");
webBrowser.DocumentText = htmlText.ToString();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With