【问题标题】:Crystal Report. The System cannot find the file specified水晶报表。该系统找不到指定的文件
【发布时间】:2020-08-10 15:30:48
【问题描述】:

当我点击加载收据时。它显示加载报告文件和内部异常为:

系统找不到指定的文件。

可能是什么问题?之前它可以工作,但现在出现问题。

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");
            }
        }

【问题讨论】:

  • 报错信息很清楚,提示找不到文件。请检查 billreports.rpt 文件是否存在于代码预期的路径中。
  • 是的,它存在

标签: c# sql-server wpf crystal-reports


【解决方案1】:

这里可能找不到文件:

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

确保文件存在并且运行程序的用户可以通过安全权限访问该文件。

另外,rpt 文件是构建的一部分吗? (bin\release) 还是 (bin\debug)?

也许编译后的版本没有找到它。

您可以将相对路径更改为绝对路径 (D:\your\path\Reports\billreports.rpt) 并测试此理论。

【讨论】:

  • 检查运行应用程序所需的用户权限。尝试以管理员身份运行它,看看是否有任何区别。
  • 抛出异常:CrystalDecisions.CrystalReports.Engine.dll 中的“System.Runtime.InteropServices.COMException”抛出异常:CrystalDecisions.CrystalReports.Engine.dll 中的“CrystalDecisions.Shared.CrystalReportsException”抛出异常:“ CrystalDecisions.CrystalReports.Engine.dll 中的 CrystalDecisions.Shared.CrystalReportsException' 加载报告失败。
【解决方案2】:

手动将 .rpt .cs 报告文件和 crystalreportviewrs13 文件夹复制到根文件夹,即

C:/inetpub/wwwroot/{ProjectName}

【讨论】:

    猜你喜欢
    • 2013-12-26
    • 1970-01-01
    • 2017-05-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多