【问题标题】:RDLC Local Report after deploy not working部署后的 RDLC 本地报告不起作用
【发布时间】:2015-10-24 15:19:41
【问题描述】:

我使用 RDLC 构建了一个带有本地报告的 Windows 应用程序,当我在 VS2012 中运行代码时它运行良好,但是当我部署它时,应用程序给了我一些错误:

本地报告处理过程中出现错误。

尚未指定报告“Report1.rdlc”的报告定义

找不到路径“C:...\Report1.rdlc”的一部分。

我正在使用的代码:

DataSet2 ds = new DataSet2();
                DataTable dt = ds.Table2;

                DataRow dr = null;
                for (int i = 0; i < dataGridView1.Rows.Count - 1; i++)
                {
                    dr = ds.Table2.NewRow();
                    dr["Nr"] = dataGridView1.Rows[i].Cells[0].Value.ToString();
                    dr["Ary"] = dataGridView1.Rows[i].Cells[1].Value.ToString();
                    dr["Car"] = dataGridView1.Rows[i].Cells[2].Value.ToString();
                    dr["Total"] = dataGridView1.Rows[i].Cells[3].Value.ToString();
                    dr["Total2"] = dataGridView1.Rows[i].Cells[4].Value.ToString();
                    // MessageBox.Show(dr["Vetura"].ToString());
                    ds.Table2.Rows.Add(dr);
                    dt.AcceptChanges();
                }

                dr.AcceptChanges();

               

                string exeFolder = (Path.GetDirectoryName(Application.StartupPath)).Substring(0, (Path.GetDirectoryName(Application.StartupPath)).Length - 3);
                string reportPath = Path.Combine(exeFolder, @"Report1.rdlc");
                //MessageBox.Show(reportPath.ToString());
                Microsoft.Reporting.WinForms.ReportDataSource rds = new Microsoft.Reporting.WinForms.ReportDataSource("DataSet2", ds.Tables[0]);
                ra.reportViewer1.LocalReport.DataSources.Clear();
                ra.reportViewer1.LocalReport.DataSources.Add(rds);
                ra.reportViewer1.LocalReport.ReportPath = reportPath;
                if (textBox2.TextLength > 0)
                {
                    ReportParameter Percentage = new Microsoft.Reporting.WinForms.ReportParameter("Percentage", "-" + textBox2.Text + "%");
                    ReportParameter Total = new Microsoft.Reporting.WinForms.ReportParameter("Total", textBox3.Text);
                    ra.reportViewer1.LocalReport.SetParameters(new ReportParameter[] { Percentage });
                    ra.reportViewer1.LocalReport.SetParameters(new ReportParameter[] { Total });
                }
                //HERE IS THE FIRST ERROR , WHEN I PASS THE THE TEXT TO THE PARAMETER
                ReportParameter Klienti = new Microsoft.Reporting.WinForms.ReportParameter("Klienti", textBox1.Text);
                ra.reportViewer1.LocalReport.SetParameters(new ReportParameter[] { Klienti });
                ra.reportViewer1.RefreshReport();

【问题讨论】:

  • 您可以尝试将工作目录设置为 exefolder,看看是否有帮助?只需打开命令提示符,将目录更改为 exe 文件夹并运行 exe
  • @GaneshR。我不太明白你的意思,将工作目录设置为 exefolder 是什么意思?
  • 假设您的 exe 在 C:\Data 中,打开命令提示符并键入 cd /d C:\Data。然后只需输入exe名称并按Enter。基本上你的应用程序工作目录设置为 c:\Data
  • 好的,我刚刚试了一下,没有错,它打开了应用程序,但是当我按下按钮来呈现 ReportViewer 时它失败了
  • blogs.msdn.com/b/selvar/archive/2014/01/20/… stackoverflow.com/questions/18650571/… 他们都要求你设置ReportPath,需要exe文件夹中的Report1.rdlc

标签: c# winforms deployment rdlc localreport


【解决方案1】:

感谢 Ganesh R.我设法解决了这个问题。 我是通过代码手动提供 ReportPath 的,所以我通过选择 ReportViewer 上的路径来自动提供它,它完成了这项工作。

【讨论】:

    猜你喜欢
    • 2015-04-28
    • 1970-01-01
    • 2022-10-07
    • 2016-11-06
    • 2022-06-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多