Click here to Skip to main content
11,704,107 members (61,525 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C# CrystalReports

i want to know about the Export the crystal report in PDF formate as well as direct save that export file in our website local folder and send in email as attachment via SMTP.

i tried and make PDF only but not success into save in our local folder as well as send as attachment of that PDF file into SMTP code.

 protected void Page_Init(object sender, EventArgs e)
        string id;
        id = Request.QueryString["id"];
        String data = "SELECT  * from Leave_record where id=" + id + "";
        SqlDataAdapter ad1 = new SqlDataAdapter(data, c.getcon());
        DataSet ds1 = new DataSet();
        path = Server.MapPath("REPORTS/leave_report.rpt");
        cr = new ReportDocument();
        string name=Server.MapPath("PDF/mitesh.pdf");
        cr.ExportToHttpResponse(ExportFormatType.PortableDocFormat, Response, false,name); // only show PDF file but not save in Website Folder
        CrystalReportViewer1.ReportSource = cr;
Please help me.
Thanks and Regards...
Posted 2-Jul-12 18:54pm
Edited 2-Jul-12 19:44pm
Damith Weerasinghe at 3-Jul-12 1:42am
can you show the code what you have tried so far?
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

May be permission issue when exporting to a folder.
You can try using temp folder as

string fileName = System.IO.Path.GetTempPath() + Guid.NewGuid().ToString() + ".pdf";

then save to temp folder

reportDocument.ExportToDisk(ExportFormatType.PortableDocFormat, fileName);

since you have the file location you can attach that to a Email.
Damith Weerasinghe at 3-Jul-12 2:40am
I'm glad it helped you :)
Member 10765474 at 6-May-14 7:00am
i tried this in my program, but it display blank page

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 745
1 OriginalGriff 520
2 Maciej Los 475
3 Andy Lanng 284
4 CPallini 275
0 OriginalGriff 8,784
1 Sergey Alexandrovich Kryukov 7,843
2 CPallini 5,107
3 Maciej Los 4,726
4 Mika Wendelius 3,606

Advertise | Privacy | Mobile
Web01 | 2.8.150819.1 | Last Updated 3 Jul 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100