Sending an email attachment in memory using OpenXML

Posted by ohnoesitsbroken on Stack Overflow See other posts from Stack Overflow or by ohnoesitsbroken
Published on 2009-06-25T13:48:23Z Indexed on 2010/04/05 18:23 UTC
Read the original article Hit count: 318

Filed under:
|

I've got an Excel file that's built using OpenXML 2 and I want to send it as an email attachment. e.g.

    System.IO.MemoryStream stream = new System.IO.MemoryStream();
    SpreadsheetDocument package = SpreadsheetDocument.Create(stream, SpreadsheetDocumentType.Workbook))
    AddParts(package); //created using document reflector

Saving the spreadsheet to a temp file using

stream.WriteTo(new System.IO.FileStream(@"c:\test.xlsx", System.IO.FileMode.Create));

works fine. But trying to send the stream directly as an email attachment fails - just get an empty file attached to the email when I do

System.Net.Mail.Attachment file = new System.Net.Mail.Attachment(stream, "MobileBill.xlsx", "application/vnd.ms-excel");

Anbody know how to do this?

© Stack Overflow or respective owner

Related posts about openxml

Related posts about email