在 RDLC 报告设计器中找不到文件

问题描述

我有一个带有 RDLC 报告的 .Net MVC 应用程序。应用程序打印证书,但在查找 rdlc 报告时出现问题。我尝试了很多事情,将 build action 更改为 contentcopy to Output 以复制如果更新,但它似乎没有解决问题.

public void PrintCertificate()
    {

        var lastEntity = db.Certificates
                   .OrderByDescending(p => p.ID)
                   .FirstOrDefault();

        var data = new DataTable();
        data.Columns.Add("ID");
        data.Columns.Add("EMP_Name");
        data.Columns.Add("Course_Title");
        data.Columns.Add("DateOfIssue");

        var row = data.NewRow();

        row["ID"] = lastEntity.ID;
        row["EMP_Name"] = lastEntity.EMP_Name;
        row["Course_Title"] = lastEntity.Course_Title;
        row["DateOfIssue"] = lastEntity.DateOfIssue;
        data.Rows.Add(row);
        Warning[] warnings;
        string[] streamIds;
        string mimeType,encoding,extension,deviceInfo = "<DeviceInfo>" +
      "  <OutputFormat>PNG</OutputFormat>" +
      "  <PageWidth>50.00000in</PageWidth>" +
      "  <PageHeight>50.00000in</PageHeight>" +
      "  <DpiX>100</DpiX>" +
      "  <DpiY>100</DpiY>" +
      "  <MarginTop>0in</MarginTop>" +
      "  <MarginLeft>0in</MarginLeft>" +
      "  <MarginRight>0in</MarginRight>" +
      "  <MarginBottom>0in</MarginBottom>" +
      "</DeviceInfo>";
        // Setup the report viewer object and get the array of bytes
        ReportViewer viewer = new ReportViewer();
        viewer.SizeToReportContent = true;
        viewer.ProcessingMode = ProcessingMode.Local;
        viewer.LocalReport.ReportPath = Server.MapPath("~/Cert_Template/AirportCommercial.rdlc");

        viewer.LocalReport.EnableExternalImages = true;
        ReportDataSource theSource = new ReportDataSource("CertificateDBDataSet",data);
        viewer.LocalReport.DataSources.Add(theSource);
        viewer.LocalReport.Refresh();
        viewer.LocalReport.DataSources.Clear();

        byte[] bytes = viewer.LocalReport.Render("PDF",deviceInfo,out mimeType,out encoding,out extension,out streamIds,out warnings);

        // Now that you have all the bytes representing the PDF report,buffer it and send it to the client.
        Response.Buffer = true;
        Response.Clear();
        Response.ContentType = mimeType;
        Response.AddHeader("content-disposition","attachment; filename" + "." + extension);
        Response.BinaryWrite(bytes); // create the file
        Response.Flush(); // send it to the client to download
    }

问题出现在这一行

byte[] bytes = viewer.LocalReport.Render("PDF",out warnings);

异常

FileNotFoundException: Could not find file 'C:\Users\ymodhi\source\repos\CertificateApplication\CertificateApp\Cert_Template\AirportCommercial.rdlc'.

用xml查看时报告版本

<Report xmlns="http://schemas.microsoft.com/sqlserver/reporting/2008/01/reportdefinition" xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner">

组装

 <assemblies>
    <add assembly="Microsoft.ReportViewer.Common,Version=15.0.0.0,Culture=neutral,PublicKeyToken=89845DCD8080CC91" />
    <add assembly="Microsoft.ReportViewer.WebForms,PublicKeyToken=89845DCD8080CC91" />
  </assemblies>

rdlc location

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...