Just pull the data out of the string writer into a byte[]
and then create a MemoryStream
passing it the byte array data, finally use the Attachements
collection of the MailMessage
class to attach it to the email to send, like this:
MailMessage mail = new MailMessage();
System.Text.Encoding theEncoding = System.Text.Encoding.ASCII;
byte[] theByteArray = theEncoding.GetBytes(sw.ToString());
MemoryStream theMemoryStream = new MemoryStream(theByteArray, false);
mail.Attachments.Add(new Attachment(theMemoryStream, "YOUR_FILE_NAME.xls"));
// Do remainder of your email settings here, To, From, Subject, etc.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…