2016-11-27 25 views
0

私は最後の2日間で問題に直面しています。私は、reportviewerなしでpdfとしてrdlcレポートを表示しようとしています。私は、クライアントPCに、このpdfファイルをレンダリングしたいUSER-> AppData->温度RDLCレポートをAsp.netのpdfとして表示MVC

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

にエクスポートした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にRDLCエクスポートします。

このコードはローカルマシンで正常に動作します。しかし、私はこれをIISサーバーに公開し、クライアントPCにエクスポートされたpdfファイルを成功させるために実行するために実行します。どうすればこの問題を解決できますか?誰でも助けてくれますか?事前に

おかげで...

答えて

1

最後に、私はasp.net MVCでPDFとして表示するRDLCレポートについての一つの解決策を見つけました。解決策は以下の通りです....

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

が、これはまだ働いているのですか? –

+0

返品時にエラーが発生するFile(filePath、 "application/pdf") –

+0

Export()メソッドをどこに追加しますか?ダイレクトコントローラーまたは別クラス?プロジェクト参照に適切なバージョンのMicrosoft.ReportViewer.WebForms.dllを追加しますか? @ElbertJohnFelipe –

関連する問題