View RDLC Report as pdf in Asp.net MVC

匿名 (未验证) 提交于 2019-12-03 08:33:39

问题:

I am facing problem in last two days. I am trying to view rdlc report as pdf without reportviewer. I export rdlc to pdf using the following code...

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

The pdf file exported to 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); 

I want to render this pdf file to the client PC.

This Code is work fine on my local machine. But when i publish this to IIS Server and run for try to get the exported pdf file to client PC not success. How can i solve this issue. Can anyone help me.

Thanks In Advance...

回答1:

Finally, i found one solution about view RDLC report as pdf in asp.net MVC. The solution is following....

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

I use the following method for generate pdf from 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;     }            } 


易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!