在Asp.net MVC中查看RDLC报告为pdf

我在最近两天遇到了问题。 我试图在没有reportviewer的情况下将rdlc报告视为pdf。 我使用以下代码将rdlc导出为pdf …

public string Export(LocalReport rpt, string filePath) { string ack = ""; try { Warning[] warnings; string[] streamids; string mimeType; string encoding; string extension; byte[] bytes = rpt.Render("PDF", null, out mimeType, out encoding, out extension, out streamids, out warnings); using (FileStream stream = File.OpenWrite(filePath)) { stream.Write(bytes, 0, bytes.Length); } return ack; } catch(Exception ex) { ack = ex.InnerException.Message; return ack; } } 

pdf文件导出到User-> AppData-> Temp

  string filePath = System.IO.Path.GetTempFileName(); string ack = Export(rpt, Server.MapPath("~/Reports/Mymun_Lab/ComparisonStudy.rdlc")); System.Diagnostics.Process.Start(filePath); 

我想将此pdf文件呈现给客户端PC。

此代码在我的本地计算机上正常工作。 但是当我将其发布到IIS服务器并运行以尝试将导出的pdf文件发送到客户端PC时不成功。 我该如何解决这个问题。 谁能帮我。

提前致谢…

最后,我在asp.net MVC中找到了一个关于视图RDLC报告为pdf的解决方案。 解决方案如下……

 public FileResult ViewReport() { string RptPath = Server.MapPath("~/Reports/Mymun_Lab/ComparisonStudy.rdlc"); Microsoft.Reporting.WebForms.LocalReport rpt = new Microsoft.Reporting.WebForms.LocalReport(); /* Bind Here Report Data Set */ rpt.ReportPath = RptPath; string filePath = System.IO.Path.GetTempFileName(); Export(rpt, filePath); //CLOSE REPORT OBJECT rpt.Dispose(); return File(filePath, "application/pdf"); } 

我使用以下方法从RDLC生成pdf ….

 public string Export(LocalReport rpt, string filePath) { string ack = ""; try { Warning[] warnings; string[] streamids; string mimeType; string encoding; string extension; byte[] bytes = rpt.Render("PDF", null, out mimeType, out encoding, out extension, out streamids, out warnings); using (FileStream stream = File.OpenWrite(filePath)) { stream.Write(bytes, 0, bytes.Length); } return ack; } catch(Exception ex) { ack = ex.InnerException.Message; return ack; } }