I have a a MailMessage object called message.
I am trying t开发者_Go百科o create the message.Body but I only have a IList to populate it with.
In the body I want the following:
"The following files could not be converted-" + IList<string> testlist
??????
StringBuilder builder = new StringBuilder("The following files could not be converted-\n");
foreach(string s in testlist)
builder.AppendFormat("{0}\n", s);
string body = builder.ToString();
var body = string.Format("The following files could not be converted-{0}.", string.Join(", ", testlist.ToArray()));
you can play around with the layout by using "\n" instead of ", " for example.
I would convert your IList to a CSV string value. The string.Join() function should help with this.
Below is code off the top of my head, so it may not work, but hopefully it gives you the idea.
IList<string> x = new List<string>();
x.Add("file1");
x.Add("file2");
string message = "The following files could not be converted: " + string.Join(", ", x.ToArray());
This is free-hand and untested, but you get the idea...
var sb = new StringBuilder();
sb.Append("The following files could not be converted:\n");
testlist.ForEach(s => sb.Append(string.Format("{0}\n", s)));
精彩评论