【发布时间】:2016-06-26 11:40:11
【问题描述】:
我在以前的项目中使用了一种生成报告的方法,并尝试在新项目中使用相同的方法。但是,我遇到 “Non-invocable member 'File' cannot be used like a method” 错误并且无法识别文件。通过查看文件的引用,在以前的项目中似乎是FileContentResult Controller.File(),但在新项目中是System.IO.File()(即使我删除 using System.IO; 从引用行中,我遇到 "The当前上下文中不存在名称“文件”” 错误)。有解决问题的想法吗?
public static FileResult GenerateReport()
{
EmployeeTableAdapter ta = new EmployeeTableAdapter();
EmployeeDS ds = new EmployeeDS();
ds.Employee.Clear();
ds.EnforceConstraints = false;
ta.Fill(ds.Employee);
ReportDataSource rds = new ReportDataSource();
rds.Name = "ReportingDataSet";
rds.Value = ds.Employee;
ReportViewer rv = new Microsoft.Reporting.WebForms.ReportViewer();
rv.ProcessingMode = ProcessingMode.Local;
rv.LocalReport.ReportPath = System.Web.HttpContext.Current.
Server.MapPath("~/Reporting/Employee.rdlc");
rv.LocalReport.EnableHyperlinks = true;
rv.LocalReport.EnableExternalImages = true;
// Add the new report datasource to the report.
rv.LocalReport.DataSources.Add(rds);
rv.LocalReport.EnableHyperlinks = true;
rv.LocalReport.Refresh();
byte[] streamBytes = null;
string mimeType = "";
string encoding = "";
string filenameExtension = "";
string[] streamids = null;
Warning[] warnings = null;
streamBytes = rv.LocalReport.Render("PDF", null, out mimeType, out
encoding, out filenameExtension, out streamids, out warnings);
return File(streamBytes, mimeType, "Application" + "_" + ".pdf");
}
注意:我使用 MVC5 和 SQL Server。
【问题讨论】:
标签: c# asp.net asp.net-mvc asp.net-mvc-4 report