Search code examples
c#sql-serverwpfcrystal-reports

Crystal Report. The System cannot find the file specified


When I click to load the receipt. It shows Load report filed and the inner exception as:

The system cannot find the file specified.

What could be the issue? Earlier it was working but now it is showing problem.

public static void loadBillReport(ReportDocument rd, CrystalReportViewer crv, Int32 status, Int32 orderID)
        {
            try
            {
                SqlCommand cmd = new SqlCommand("getOrderReport", MainClass.con);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@orderID", orderID);
                cmd.Parameters.AddWithValue("@status", status);
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                DataTable dt = new DataTable();
                da.Fill(dt);
                rd.Load(Application.StartupPath + "\\Reports\\billreports.rpt");
                rd.SetDataSource(dt);
                crv.ReportSource = rd;
                crv.RefreshReport();
            }
            catch (Exception ex)
            {
                if (rd != null)
                {
                    Console.WriteLine(ex.Message);
                    rd.Close();
                }
                MainClass.showMessage(ex.Message, "Error");
            }
        }

Solution

  • It is probably not finding the file here:

    rd.Load(Application.StartupPath + "\Reports\billreports.rpt"); 
    

    Make sure the file exists and the user which is running the program has access to the file via security permissions.

    Also, is the rpt file a part of the build? (bin\release) or (bin\debug)?

    Maybe the compiled version isn't finding it.

    You can change the relative path to absolute path (D:\your\path\Reports\billreports.rpt) and test this theory.