系统找不到为某些水晶报告指定的路径

时间:2015-07-23 12:36:07

标签: c# asp.net-mvc crystal-reports

我在MVC应用程序中使用Crystal Reports最新版本。 1报告工作正常,但在加载其他报告时连续发生非常奇怪的错误。我使用过Switch语句。第一个案例的报告运行正常。但在其他情况下总会出现错误:

类型' System.Runtime.InteropServices.COMException'的异常发生在myapp.dll中但未在用户代码中处理 附加信息: 系统找不到指定的路径。

public ActionResult SeeReport(FormCollection f)
{
    ReportDocument rd = new ReportDocument();

    string s = f["rptname"];
    switch (s)
    {
        case ("011501"):
        {
            DataSet ds = new DataSet();

            CommonProcs_AHPI.CommonProcess xRptProcess = new CommonProcs_AHPI.CommonProcess();
            ds.ExtendedProperties["index"] = 1150101;//13502 013501_3
            DataTable xDTR = new DataTable();
            xDTR.TableName = "_rpTitle_";

            xDTR.Columns.Add("N100", System.Type.GetType("System.Double"));
            xDTR.Columns.Add("S100", System.Type.GetType("System.String"));
            xDTR.Columns.Add("S101", System.Type.GetType("System.String"));
            xDTR.Columns.Add("S102", System.Type.GetType("System.String"));
            xDTR.Columns.Add("S1", System.Type.GetType("System.String"));
            xDTR.Columns.Add("S2", System.Type.GetType("System.String"));
            xDTR.Columns.Add("S3", System.Type.GetType("System.String"));
            xDTR.Columns.Add("S4", System.Type.GetType("System.String"));
            xDTR.Columns.Add("S5", System.Type.GetType("System.String"));
            xDTR.Columns.Add("S6", System.Type.GetType("System.String"));
            ds.Tables.Add(xDTR);

            DataTable xDT = new DataTable();
            xDT.TableName = "rpdata";
            xDT.Columns.Add("S102", System.Type.GetType("System.String"));
            xDT.Columns.Add("S107", System.Type.GetType("System.String"));
            xDT.Columns.Add("S20", System.Type.GetType("System.String"));
            xDT.Columns.Add("S21", System.Type.GetType("System.String"));
            xDT.Columns.Add("S22", System.Type.GetType("System.String"));
            xDT.Columns.Add("S23", System.Type.GetType("System.String"));
            xDT.Columns.Add("S24", System.Type.GetType("System.String"));
            xDT.Columns.Add("S25", System.Type.GetType("System.String"));

            DataRow xRow = xDT.NewRow();

            xRow["S102"] = "1";
            xRow["S21"] = "4";
            xRow["S22"] = f["begin_code"];
            xRow["S23"] = f["end_code"];
            xRow["S24"] = "N";
            xRow["S25"] = "";
            xDT.Rows.Add(xRow);
            ds.Tables.Add(xDT);
            xDT.AcceptChanges();

            ds = xRptProcess.ProcessCall(ds);

            rd.Load(Path.Combine(Server.MapPath("~/RPTGL_AHPI/"), "011501.rpt"));
            rd.SetDataSource(ds);
            Response.Buffer = false;
            Response.ClearContent();
            Response.ClearHeaders();

            break;
        }
        case ("013501_3"):
        {
            DataSet ds = new DataSet();

            CommonProcs_AHPI.CommonProcess xRptProcess = new CommonProcs_AHPI.CommonProcess();
            ds.ExtendedProperties["index"] = 13502;
            DataTable xDTR = new DataTable();
            xDTR.TableName = "_rpTitle_";

            xDTR.Columns.Add("N100", System.Type.GetType("System.Double"));
            xDTR.Columns.Add("S100", System.Type.GetType("System.String"));
            xDTR.Columns.Add("S101", System.Type.GetType("System.String"));
            xDTR.Columns.Add("S102", System.Type.GetType("System.String"));
            xDTR.Columns.Add("S1", System.Type.GetType("System.String"));
            xDTR.Columns.Add("S2", System.Type.GetType("System.String"));
            xDTR.Columns.Add("S3", System.Type.GetType("System.String"));
            xDTR.Columns.Add("S4", System.Type.GetType("System.String"));
            xDTR.Columns.Add("S5", System.Type.GetType("System.String"));
            xDTR.Columns.Add("S6", System.Type.GetType("System.String"));
            ds.Tables.Add(xDTR);

            DataTable xDT = new DataTable();
            xDT.TableName = "rpdata";
            xDT.Columns.Add("S102", System.Type.GetType("System.String"));
            xDT.Columns.Add("S107", System.Type.GetType("System.String"));
            xDT.Columns.Add("S20", System.Type.GetType("System.String"));
            xDT.Columns.Add("S21", System.Type.GetType("System.String"));
            xDT.Columns.Add("S22", System.Type.GetType("System.String"));
            xDT.Columns.Add("S23", System.Type.GetType("System.String"));
            xDT.Columns.Add("S24", System.Type.GetType("System.String"));
            xDT.Columns.Add("S25", System.Type.GetType("System.String"));
            xDT.Columns.Add("D1", System.Type.GetType("System.DateTime"));
            xDT.Columns.Add("D2", System.Type.GetType("System.DateTime"));

            DataRow xRow = xDT.NewRow();

            xRow["S102"] = "1";
            //xRow["S21"] = "4";
            xRow["S21"] = f["begin_code"];
            xRow["S22"] = f["end_code"];
            xRow["S23"] = "1";
            xRow["S24"] = "0";
            xRow["S25"] = "";
            xRow["D1"]  = Convert.ToDateTime(f["begin_date"]);
            xRow["D2"]  = Convert.ToDateTime(f["end_date"]);
            xDT.Rows.Add(xRow);
            ds.Tables.Add(xDT);
            xDT.AcceptChanges();

            ds = xRptProcess.ProcessCall(ds);

            rd.Load(Path.Combine(Server.MapPath("~/Report/"), "013501_3.rpt"));
            rd.SetDataSource(ds);
            rd.Refresh();
            Response.Buffer = false;
            Response.ClearContent();
            Response.ClearHeaders();

            break;

        }


    }

    try
    {
        Stream stream = rd.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
        stream.Seek(0, SeekOrigin.Begin);
        return File(stream, "application/pdf", "Report.pdf");
    }
    catch (Exception ex)
    {
        throw;
    }
}

第一种情况正常,报告已成功下载,但所有其他报告都会产生上述错误。

1 个答案:

答案 0 :(得分:0)

我明白了...我的报告是错误的。错误"系统无法找到指定的路径"非常误导。实际上,当报告转到STREAM时,它会查找报告数据,但由于它已损坏,因此它没有获取指定的报告并抛出未找到的路径的异常。 我通过在我的应用程序中创建一个WPF应用程序并从那里查看报告来解决它,然后我得到了关于我的报告的真正错误。