C# 在Asp.net MVC中以pdf格式查看RDLC报告
在过去的两天里,我面临着这个问题。我试图在没有reportviewer的情况下以pdf格式查看rdlc报告。我使用以下代码将rdlc导出为pdfC# 在Asp.net MVC中以pdf格式查看RDLC报告,c#,asp.net-mvc,asp.net-mvc-4,pdf-generation,rdlc,C#,Asp.net Mvc,Asp.net Mvc 4,Pdf Generation,Rdlc,在过去的两天里,我面临着这个问题。我试图在没有reportviewer的情况下以pdf格式查看rdlc报告。我使用以下代码将rdlc导出为pdf public string Export(LocalReport rpt, string filePath) { string ack = ""; try { Warning[] warnings; string[]
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;
}
}
导出到User->AppData->Temp的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不成功。我怎样才能解决这个问题。有人能帮我吗
提前感谢…最后,我找到了一个在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;
}
}
最后,我找到了一个在asp.NETMVC中以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;
}
}
在您添加Export()方法的返回文件(filePath,“application/pdf”)中出现错误?直接在控制器中还是单独的类中?是否在项目参考中添加了正确版本的Microsoft.ReportViewer.WebForms.dll@ElbertJohnFelipeI在您添加Export()方法的返回文件(filePath,“application/pdf”)中获取错误?直接在控制器中还是单独的类中?是否在项目参考中添加了正确版本的Microsoft.ReportViewer.WebForms.dll@埃尔伯特约翰费利佩