Click here to Skip to main content
15,891,657 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Helloo,

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"];
        c.setcon();
        String data = "SELECT  * from Leave_record where id=" + id + "";
        SqlDataAdapter ad1 = new SqlDataAdapter(data, c.getcon());
        DataSet ds1 = new DataSet();
        ad1.Fill(ds1);

        path = Server.MapPath("REPORTS/leave_report.rpt");
        cr = new ReportDocument();
        cr.Load(path);

        cr.SetDataSource(ds1.Tables[0]);

        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...
Mitesh
Posted
Updated 2-Jul-12 19:44pm
v2
Comments
DamithSL 3-Jul-12 1:42am    
can you show the code what you have tried so far?

 
Share this answer
 
Comments
[no name] 3-Jul-12 1:36am    
Dear, when i write CrExportOptions = cryRpt.ExportOptions; statement the Exportoption not showing in my code. So what can i do ?
crypt is my ReportDocument.
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.
 
Share this answer
 
v2
Comments
[no name] 3-Jul-12 1:58am    
Dear, or possible to direct send that PDF file as attachment using SMTP code without save to local folder of our website. if yes, please tell me with some code or Correct me for right way....
[no name] 3-Jul-12 2:26am    
i solved it by Your Answer. Thanks Brother......
[no name] 3-Jul-12 2:26am    
My 555+++++
DamithSL 3-Jul-12 2:40am    
I'm glad it helped you :)
Member 10765474 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)



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