Saving to Stream (Email attachment) results in empty file

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.

Hi,

Well, I don’t find any issue.

Following is my testing code:

//Instantiate a new Workbook object.
Workbook workbook = new Workbook();
Aspose.Cells.Worksheet worksheet = workbook.Worksheets[0];
Aspose.Cells.Cell cell = worksheet.Cells[“A1”];
cell.PutValue(“testing123…”);
MemoryStream ms = new MemoryStream();
ms = workbook.SaveToStream();
workbook.Save(ms, Aspose.Cells.FileFormatType.Default);
ms.Seek(0, SeekOrigin.Begin);
MailMessage message = new MailMessage("", “”);
message.Subject = “Aspose Testing Excel File As Attachment”;
message.Body = “Message Body… This is message Body”;
message.Attachments.Add(new Attachment(ms, “myfile_test2”, “application/vnd.ms-excel”));
SmtpClient client = new SmtpClient();
client.Host = “”;
client.Port = ;
client.EnableSsl = true;
client.Send(message);


Thank you.