Click here to Skip to main content
15,888,984 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear sir

I am Shailendra singh ,I am fresher and I am not doing following work.How can convert crystal Report to PDF File in asp.net.But My database is online .Please any one help me.





Thank you In Advance.
Posted

Hi Shailendra,

There is built in methods available from crystal report to convert it into different formats

After binding your crystal report below is the code for exporting it into pdf format.
ExportOptions exportOpts = doc.ExportOptions;
exportOpts.ExportFormatType = ExportFormatType.PortableDocFormat;
exportOpts.ExportDestinationType = ExportDestinationType.DiskFile;
exportOpts.DestinationOptions = new DiskFileDestinationOptions();
XML
DiskFileDestinationOptions diskOpts = new DiskFileDestinationOptions();
            ( ( DiskFileDestinationOptions )doc.ExportOptions.DestinationOptions ).DiskFileName = Server.MapPath("fin.pdf");
            doc.Export();
            Response.Write(dt.Rows.Count);
            Response.Write("<a href=\"" + pdfFile + "\">" + pdfFile + "</a>"

);


If you want to provide selection of export format there is built in option in crystal report viewer.

Hope this helps
 
Share this answer
 
Comments
deepakdynamite 18-Nov-11 1:41am    
nice one
Crystal reports itself support this . As far as i know you just need to export crystal report and it will ask for the format and path
 
Share this answer
 
Hi Shailendra,

To convert Crystal Report into PDF u have follow some steps:

Add Crystal Report View into ur page

and the try my code to convert

DataTable dt = new DataTable();

//below Datatable call ur class and method,
dt = Designation.fillgrid();
try
{
if (dt.Rows.Count &gt; 0)
{
ReportDocument rptdoc = new ReportDocument();
//here u will give ur path Like I have give There folder report in which I kept the DesignationReport.rpt

rptdoc.Load(Server.MapPath("~\\Report\\DesignationReport.rpt"));
rptdoc.SetDataSource(dt);

//crv is the ID of crystal Report viewer
crv.ReportSource = rptdoc;
crv.DataBind();


ExportOptions exportOpts1 = rptdoc.ExportOptions;
rptdoc.ExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
rptdoc.ExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
rptdoc.ExportOptions.DestinationOptions = new DiskFileDestinationOptions();
((DiskFileDestinationOptions)rptdoc.ExportOptions.DestinationOptions).DiskFileName = Server.MapPath("DesignationReport.pdf");
rptdoc.Export();
rptdoc.Close();
rptdoc.Dispose();
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = "application/pdf";
Response.AppendHeader("Content-Disposition", "attachment; filename=DesignationReport.pdf");
Response.WriteFile("DesignationReport.pdf");
Response.Flush();
Response.Close();
System.IO.File.Delete(Server.MapPath("DesignationReport.pdf"));
}
else
{
Messagebox1.Show("No Record for this District");
}
}
catch { }
}

After trying above code give feedbacks
 
Share this answer
 

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