I see you have a coding example for a System.IO.FileStream attachment, but I can't seem to find one for a System.IO.MemoryStream attachment. I don't want to have the attachment saved on my user's pc. I want to take the .pdf they create dynamically and attach it via MemoryStream. Thanks for your help!!
Using MemoryStream For Attachment
Re: Using MemoryStream For Attachment
Support · Dec 13, 2007Hello,
The Attachment object contructor can take either a byte array, a string (filepath) or it can take a System.IO.Stream. The Stream object does not need to be a FileStream but rather could be any type derived form the System.IO.Stream class (i.e MemoryStream).
One additional thing to keep in mind here is that you need to make sure that you seek back to the beginning of the Stream before passing it into the Attachment constructor.
Thanks,
ceTe Software Support Team
Re: Using MemoryStream For Attachment
Forum member · Dec 13, 2007Do you have a coding example for MemoryStream objects as attachments?
Thanks!
Re: Using MemoryStream For Attachment
Forum member · Dec 13, 2007Nevermind -- I got it to work! Thanks for your help...
Re: Using MemoryStream For Attachment
Support · Dec 13, 2007Hello,
Following is the sample C# code that shows generated PDF document directly using the MemoryStream:
ceTe.DynamicPDF.Document document = new ceTe.DynamicPDF.Document();
ceTe.DynamicPDF.Page page = new ceTe.DynamicPDF.Page( PageSize.Letter, PageOrientation.Portrait, 54.0f );
string text = "Hello ASPX C# World...\nFrom DynamicPDF™ Generator for .NET\nDynamicPDF.com";
Label label = new Label( text, 0, 0, 504, 100, Font.Helvetica, 18, TextAlign.Center );
page.Elements.Add( label );
document.Pages.Add( page );
System.IO.MemoryStream stream = new System.IO.MemoryStream();
PlainTextMessage ptMessage = new PlainTextMessage("xyz@xyz.com", "xyz@xyz.com", "Mail with Stream Attachment", " Files Attached");
ptMessage.Attachments.Add(document.Draw( stream ), "HelloWorld.pdf");
ptMessage.Send(smtpServer);
Thanks,
ceTe Software Support Team