-
Generating Charts from Data in MMSQL and sending them as attachment (PDF) in email
over 8 years ago
-
over 8 years ago
Hi Andrew,
You are using asp.net so you can use RDLC for your reporting. Now if you want to know about RDLC or how to work with RDLC in Asp.net take a look at following link:
Creating RDLC Report in Asp.Net
You can save those reports as PDF manually(as there is an option in the report viewer) or by code. I am sharing some code snippets which you can use for your solution.
For converting your reports to a PDF:private string ExportReportToPDF(string reportNamewithFullPath) { Warning[] warnings; string[] streamids; string mimeType; string encoding; string filenameExtension; byte[] bytes = ReportViewer1.LocalReport.Render( "PDF", null, out mimeType, out encoding, out filenameExtension, out streamids, out warnings); string filename = Path.Combine(Path.GetTempPath(), reportNamewithFullPath); using (var fs = new FileStream(filename, FileMode.Create)) { fs.Write(bytes, 0, bytes.Length); fs.Close(); } return filename; }
For sending that pdf via mail:
private void BtnSendByMail_Click(object sender, EventArgs e) { Mail mail = sendMailView.CurrentItem;//some mail helper class. you can use your own mail.AttachmentFiles.Add(ExportReportToPDF(yourRdlcReportPath)); mail.DeleteFilesAfterSend = true; mail.RequireAutentication = true; mail.Send(); }
So these are the two methods which you can combine to create complete code as per your requirement.
-
1 Answer(s)