微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决在 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 举报,一经查实,本站将立刻删除。