StringBuilder AppendFormat Method to Create a Table

I have a problem with the AppendFormat method of the StringBuilder class. I create a table and add data to the string builders object to send it as mail, but when I saw the mail I sent, it does not look like a table, its title and corresponding contents are not marked. I want the table to be separated by lines, as is usually the case with the Microsoft word table. how can I achieve this .. I am using the following code: Body is a StringBuilder object

if ( dic1 != null ) { //Body.AppendFormat("Client: " + cl + " Success. " + dic1.Count + " :"); Body.AppendFormat("<br/><table>"); Body.AppendFormat("<h1><tr><td>#</td><td>Files Name</td></tr></h1>"); int count = 1; foreach ((KeyValuePair<string, string> pair in dic1) { if (!String.IsNullOrEmpty(pair.Key)) { Body.AppendFormat("<tr><td>"+count.ToString()+"</td><td>" + pair.Key + "</td><td> " + pair.Value + "</td></tr>"); count++; //Body.Append( ); } } Body.AppendFormat("</table>"); 

After the output, I get in my inbox.

  # File Name Error 1 txt1.txt Loading File 'txt1.txt' failed: The specified File already exists in the system 2 txt2.txt Loading File 'txt2.txt' failed: The specified File already exists in the system 3 txt3.txt Loading File 'txt3.txt' failed: The specified File already exists in the system 
+4
source share
2 answers

I hope you can use this example to understand how it should be. If not, please let me know. I will help you.

 System.Text.StringBuilder sb = new System.Text.StringBuilder(); sb.Append("<table>"); sb.AppendFormat("<tr><td>Request Name:</td><td>{0}</td></tr>", txtBugName.Text.Trim()); sb.AppendFormat("<tr><td>Category:</td><td>{0}</td></tr>", ddlModule.SelectedValue); sb.AppendFormat("<tr><td>Sub-Category:</td><td>{0}</td></tr>", ddlPage.SelectedValue); sb.AppendFormat("<tr><td>Description:</td><td>{0}</td></tr>", txtComments.Text.Trim()); sb.AppendFormat("<tr><td>Email is:</td><td>{0}</td></tr>", txtemail.Text.Trim()); sb.Append("<table>"); 

Then I assume that the IsBodyHtml property is true, since you already used HTML

+4
source

Do something like this

  String to, subject, message; bool isHtml; isHtml = true; StringBuilder sbEmail = new StringBuilder(); to = " abc@abc.com "; // string url = "xxxxx"; // string refurl = Request.UrlReferrer.ToString(); subject = "Some subject"; // Keep Option for Otehr Language also by defining predefined // Hidden Labels for Message in L1, L2, L3, L4, L5 -- // Also add dir tag to the Table sbEmail.Append("<table><tr><td style='font-family: Arial; font-size: 10pt;'>"); sbEmail.Append("Hello,"); sbEmail.Append("<br><br>"); sbEmail.Append(""); sbEmail.Append("Following Comments has been posted"); sbEmail.Append("<br><br>"); sbEmail.Append(strComment); sbEmail.Append("<br><br>"); sbEmail.Append("Article Title :"); sbEmail.Append("<br>"); sbEmail.Append(strArticleTitle); sbEmail.Append("<br><br>"); sbEmail.Append("Name : " + strName); sbEmail.Append("<br>"); sbEmail.Append("Country : " + strCountry); sbEmail.Append("<br><br>"); sbEmail.Append("Please logon to admin section of website to activate this comments"); sbEmail.Append("<br>"); sbEmail.Append("http://xxxxx"); sbEmail.Append("</td></tr></table>"); message = sbEmail.ToString(); 
0
source

Source: https://habr.com/ru/post/1433340/


All Articles