Click here to Skip to main content
15,880,796 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
hi,


i find out an article to create pdf file

http://www.aspdotnet-suresh.com/2013/05/aspnet-export-webpage-with-images-to.html[^]


also i find an article to send email as smtp mailing in asp.net c#

http://csharpdotnetfreak.blogspot.com/2009/10/send-email-with-attachment-in-aspnet.html[^]

i also find this article also..
http://www.aspdotnet-suresh.com/2012/09/how-to-send-gridview-in-email-body-in.html[^]


i need to send the dynamically generated pdf as attach file and send to specified email address.
Posted

Ok, that's simple.

  • Pipe the pdf through a MemoryStream
    C#
    MemoryStream ms = new MemoryStream();
  • Write the pdf to the MemoryStream
    C#
    Document doc = new Document(PageSize.A4, 10f, 10f, 100f, 0.0f);
    //require custom parsers? add here.
    PdfWriter writer = PdfWriter.GetInstance(doc, ms);
    doc.Open(); //open doc for editing
    
    //do layout
    //doc.Add(new Paragraph("First Paragraph"));
    //doc.Add(new Paragraph("Second Paragraph"));
    
    writer.CloseStream = false; //important
    doc.Close(); //build the doc.
    
    memoryStream.Position = 0; //reset stream... important
  • Add the stream as attachment to the mail body!
    C#
    mail.Attachments.Add(new Attachment(ms, "filename.pdf"));
  • Send it!
    C#
    smtp.Send(mail);


Good Luck!
 
Share this answer
 
Comments
abey e mathews 30-May-13 7:22am    
i am unable to do this ..i tryed.. but showing error
AlphaDeltaTheta 30-May-13 7:55am    
What error?? Please tell
abey e mathews 30-May-13 23:35pm    
error is at memoryStream.Position = 0;
AlphaDeltaTheta 30-May-13 23:38pm    
Ok... but tell the kind of eror or message... Is is cannot seek exception or ObjectDisposed or IOException??
abey e mathews 30-May-13 23:43pm    
i correct the problem by memoryStream.Position = 0; changing to ms.Position=0;


but i done the work but problem it received 0kb pdf file(email) with out any condent
 
Share this answer
 
Comments
Deepu S Nair 16-Apr-15 2:57am    
Answering old questions adds nothing and is likely to attract
downvoting.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900