Hi..Friends,
In my web application there is a page for invoicing...The invoice format is in CK Editor.
At submit button i want to save the information in database and convert the CK content in .pdf format and attach it with mail. So that i can send invoice to clients through mail as an attachment in .pdf format....
Hi...All
I have converted CK content dynamically using iTextsharp.dll through the memory stream, It converts content into pdf and successfully attach it with mail but when i download the invoice pdf from mail it downloaded but not opened. It shows the error like "There was an error opening this document. The file is damaged and could not be repaired."
I have used following code (called the function at button click) :
private void SendMail()
{
#region Code to convert ck content in pdf memory stream
MemoryStream mstream = new MemoryStream();
Document document = new Document(PageSize.A4, 20f, 20f, 20f, 20f);
PdfWriter writer = PdfWriter.GetInstance(document, mstream);
document.Open();
document.Add(new Paragraph("INVOICE"));
document.Add(new Paragraph(txt_invoice.Text));
#endregion
string mailTo = txt_mailTo.Text.Trim().Replace("'", "''").ToString();
string msgSubject = txt_mailSubject.Text.ToString();
string msgBody = "This invoice is generated for you by impact infomedia services";
System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage("xxxxxxxxxxxx.in", mailTo, msgSubject, msgBody);
mstream.Position = 0;
mail.Attachments.Add(new Attachment(mstream, "Invoice.pdf"));
mail.IsBodyHtml = true;
SmtpClient client = new SmtpClient();
client.Host = "host name is here";
client.Port = 25;
client.Credentials = new NetworkCredential("xxxxxxxxxxx", "xxxxxxxxxxxx");
client.Send(mail);
document.Close();
mstream.Flush();
mstream.Close();
lbl_msg.Visible = true;
lbl_msg.Text = "E-mail has been sent successfully";
lbl_msg.ForeColor = System.Drawing.Color.Green;
txt_mailSubject.Text = "";
txt_mailTo.Text = "";
}
Please trace my error or help me...