2016-11-27 60 views
0

我在过去两天中遇到了问题。我正在尝试将rdlc报告视为没有reportviewer的pdf。我RDLC导出到使用下面的代码的PDF ...在Asp.net MVC中查看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; 
     }   
    } 

出口到用户 - > AppData- PDF文件>临时

  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不成功。我该如何解决这个问题。谁能帮我。

在此先感谢...

回答

1

最后,我发现有关视图RDLC报告在asp.net MVC 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"); 
    } 

我用来生成PDF RDLC以下方法....

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; 
    }   
} 
+0

是这还工作吗? –

+0

我得到返回文件(filePath,“application/pdf”) –

+0

在哪里添加Export()方法?直接在控制器或单独的类?您是否在您的项目参考中添加了适当版本的Microsoft.ReportViewer.WebForms.dll? @ElbertJohnFelipe –