Reputation: 65
I created one application in C# .Net for viewing crystal report. But when I tried to execute it, it showed:
An unhandled exception of type 'CrystalDecisions.Shared.CrystalReportsException' occurred in CrystalDecisions.CrystalReports.Engine.dll Additional information: Load report failed..
This is what I have tried:
connect();
sql = "select INVOICE.[InvoiceNo], [InvoiceDate],[CustId],Subtotal,Pid,Qty ,Rate,amount from INVOICE inner join invoicedetails on INVOICE.[InvoiceNO]= invoicedetails.[InvoicoNo] where invoicedetails.[InvoicoNo] = '" + INVID+ "' ";
objcmd = new SqlCommand(sql, objcon);
objda.SelectCommand = objcmd;
Mydataset.Clear();
objda.Fill(Mydataset "dis");
path.Load(Application.StartupPath + "C:\\Report_InvoiceRPT.rpt");
path.SetDataSource(Mydataset.Tables["dis"]);
crystalReportViewer1.ReportSource = path;
crystalReportViewer1.RefreshReport();
The following is the line that is giving me the error:
path.Load(Application.StartupPath + "C:\\Report_InvoiceRPT.rpt");
Upvotes: 0
Views: 1725
Reputation: 2649
What kind of path are you expecting to have with Application.StartupPath + "C:\\Report_InvoiceRPT.rpt"
?
This path does not exist. You are concatenating the application startup path with hard coded file path C:\\Report_InvoiceRPT.rpt
.
Always use Path.Combine()
to combine two string paths. This way you avoid double path separators since Path.Combine()
checks whether the first path has already a separator at the end so it will not duplicate the separators. Additionally, it checks whether the path elements to combine have invalid characters.
An additional check File.Exists()
would only make your application more robust.
Upvotes: 1