Ram Ram - 9 days ago 7
C# Question

Load report failed in Crystal Report

I am trying to export crystal report into pdf in Windows Form application.My Crystal Report is getting data from the Mysql Database.Here is my code for the same..

ReportDocument doc = new ReportDocument();
doc.Load("CrystalReport1.rpt");
doc.SetDataSource(dttable);

SaveFileDialog saveas = new SaveFileDialog();
saveas.Filter = "*.pdf|(PDF File)";
if (saveas.ShowDialog() == DialogResult.OK)
{

doc.ExportToDisk(ExportFormatType.PortableDocFormat, saveas.FileName + ".pdf");
MessageBox.Show("Report Exported !");

}


On running the above code. I am getting error


'Load report failed' at line
doc.Load("CrystalReport1.rpt");



Please help me resolve this.

Answer

I think the error seems to be the path of your report.

Let's try this:

doc.Load(AppDomain.CurrentDomain.BaseDirectory + "CrystalReport1.rpt");

Ludo