问题描述
最近两天我遇到了问题.我正在尝试在没有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中找到了一种以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;
}
}
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...
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;
}
}
这篇关于在Asp.net MVC中以pdf格式查看RDLC报告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!