简体   繁体   中英

Send pdf as an attachment in email

My current application send an .rtf in an attachement. I wish to send pdf instead of that. Where in my code I should modify the same?

Below is my code

        RichTextBox rtbReport = new RichTextBox();   //Creating instance of Richtextbox
        AppResult objResult = null;                  //Object of Class
        frmExaminationReport objReport = new frmExaminationReport(examinationID,   ProviderID, PatientID, examType);                        // Object of Class
        AddressBookDataTable dtAddress = null;
        rtbReport.Rtf = objReport.RTF;               // Entire Result is assigned to Richtext box class
         frmMail objMail = new frmMail();            //Object of Mail Class
         string directoryPath = Application.StartupPath + "\\Temp"; //Creating directory

         string tempFileName = "Report_" + DateTime.Today.Year.ToString() +  DateTime.Today.Month.ToString() + ".rtf";      //Generating Name
            FileStream fsReport = new FileStream(directoryPath + "\\" + tempFileName, FileMode.CreateNew);                            // FileStream
            fsReport.Write(ASCIIEncoding.ASCII.GetBytes(rtbReport.Rtf), 0, rtbReport.Rtf.Length);                         // Writing
            fsReport.Flush();
            fsReport.Close();
            fsReport.Dispose();
            objMail.MailSubject = examType + " Report";   //Mail Subject

Let me know if any inputs needed

Your code is incomplete or does not make sense (only for me?). Here is a simple tutorial to send email with attachment.

If you are generating PDF documents using your code then checkout some related questions in SO.

I don't think you can simply change .rtf to .pdf to generate PDF documents.

string tempFileName = examType + "Report_" + DateTime.Today.Year.ToString() +  DateTime.Today.Month.ToString() + ".rtf"; 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM