Bayers Rock
Bayers Rock

Reputation: 3

How can I format C# string output to contain newlines?

strEmail = 
    "Hi All," 
    + "<br>"
    + "The User " 
    + lstDataSender[0].ReturnDataset.Tables[0].Rows[0][1].ToString()
    + " has been created on " 
    + DateTime.Now.ToShortDateString() 
    + "." 

I am writing C# code to generate an email whenever a new user has been created. I need the body of the mail in a mail format like

hi,

  The user "xxx" has been created on "todaysdate".


Thanks,
yyyy

so I need to insert linebreaks and bold for some characters. How might I achieve this?

Upvotes: 0

Views: 1968

Answers (3)

In order to form, you can use like below:

Response.Write("Hi,<br/><br/>The user.......");

Upvotes: 0

TheCodeKing
TheCodeKing

Reputation: 19220

If this is a plain text email (which it looks like it is), use \r\n for new lines.

strEmail = string.Concat("Hi All,\r\n\r\nThe User",
             lstDataSender[0].ReturnDataset.Tables[0].Rows[0][1].ToString(),
             "has been created on ",
             DateTime.Now.ToShortDateString(),
             ".\r\n\r\nThanks, yyyy");

Strickly speaking this should be Environment.NewLine to support different platforms, but I doubt this is a concern.

Upvotes: 1

Dennis Traub
Dennis Traub

Reputation: 51634

Set

yourMessage.IsBodyHtml = true

Msdn-Reference can be found here.

Upvotes: 0

Related Questions