Hello I have the following code which saves the workbook as an attchment to an email.
MailMessage email = new MailMessage(fromAddress, address, subject, bodytext);
MemoryStream dstStream = new MemoryStream();
dstStream.Position = 0;
Attachment attachment = null;
if (asPDF)
{
workbook.Save(dstStream, FileFormatType.Pdf);
attachment = new Attachment(dstStream,filename.Replace(".xls",".pdf"));
}
else
{
workbook.Save(dstStream,FileFormatType.Default);
attachment = new Attachment(dstStream, filename);
}
email.Attachments.Add(attachment);
SmtpClient smtp = new SmtpClient(smtpServer, smtpPort);
smtp.Send(email);
The PDF branch works correctly and an email with the PDF attachment is as expected however the excel one does not, find attached the file that is created. The file appears to be empty. Is there a known issue Saveing FileFormatType.Default to a stream.