Pomster
Pomster

Reputation: 15207

How to format a String to display on multiple Lines

Here i have a message string that displays the content of an email. I would like the From, The subject and the body to all display on a new line.

Could someone please advise on how this is done. Below is what i'm trying but its all still on one line.

I thought enviroment.newline would work, i still think it will but maby im doing it wrong?

MessageString = "From: " + message.Headers.From.Address + Environment.NewLine + "Subject: " + message.Headers.Subject + Environment.NewLine + "Body: " + messagePart.BodyEncoding.GetString(messagePart.Body);

if you could also show me how to write code over multiple lines and still have it function that would be awesome too???????


Upvotes: 1

Views: 947

Answers (2)

Matthias Meid
Matthias Meid

Reputation: 12521

You can also use a Literal control with Mode set to PassThrough, and then use <br /> for a line break. Literals (and I guess also labels) HTML-encode their content, so a <br /> is not rendered as a line break by default.

However, be careful: You have to avoid XSS attacks on your own this way! The HttpUtility.HtmlEncode method is useful therefor.

Upvotes: 0

empi
empi

Reputation: 15901

If email is in html format then try <br />

Upvotes: 2

Related Questions