2016-11-27 3 views
0

Ich habe Probleme in den letzten zwei Tagen. Ich versuche, rdlc Bericht als pdf ohne reportviewer anzusehen. Ich exportiere rdlc zu pdf mit dem folgenden Code ...Zeige RDLC Bericht als pdf in Asp.net MVC

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

Die PDF-Datei exportiert 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); 

ich diese pdf-Datei auf dem Client-PC machen möchten.

Dieser Code funktioniert auf meinem lokalen Computer einwandfrei. Aber wenn ich dies auf IIS Server veröffentlichen und versuche, die exportierte PDF-Datei zum Client-PC zu bekommen, ist das kein Erfolg. Wie kann ich dieses Problem lösen? Kann mir jemand helfen. Voraus

Dank in den ...

Antwort

1

Schließlich fand ich eine Lösung über Ansicht RDLC Bericht als pdf in asp.net MVC. Die Lösung folgt ....

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"); 
    } 

ich die folgende Methode verwenden für pdf von RDLC erzeugen ....

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

ist dies immer noch zu arbeiten? –

+0

Ich erhalte einen Fehler in der Datei (filePath, "application/pdf") –

+0

Wo fügen Sie die Export() Methode hinzu? Direkt in Controller oder separate Klasse? Fügen Sie in Ihrer Projektreferenz die richtige Version von Microsoft.ReportViewer.WebForms.dll hinzu? @ElbertJohnFelipe –

Verwandte Themen