不可报告成员'File'不能像生成报告时那样使用

编程入门 行业动态 更新时间:2024-10-28 19:21:37
本文介绍了不可报告成员'File'不能像生成报告时那样使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在以前的项目中使用了一种生成报告的方法,并试图在新项目中使用相同的方法.但是,我遇到 不可发音的成员'File'不能像方法一样使用" 错误,并且无法识别File.通过查看文件的引用,它似乎在先前项目中为FileContentResult Controller.File(),但是在新项目中为System.IO.File()(即使我使用System.IO删除;从引用行中,我遇到名称文件"在当前上下文中不存在".有解决问题的主意吗?

I used a method for generating report in my previous project and tried to use the same method in the new project. However, I encounter "Non-invocable member 'File' cannot be used like a method" error and File cannot be recognized. By looking at the references of file, it seems to be FileContentResult Controller.File() in the previous project, but System.IO.File() in the new project (even if I remove using System.IO; from the references lines, I encounter "The name 'File' does not exist in the current context" error). Any idea to fix the problem?

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.

Note: I use MVC5 and SQL Server.

推荐答案

将方法移至 Controller 可以解决此问题.非常感谢@AlexanderDerck的帮助.

Moving the method to the Controller solved the problem. Thanks a lot @AlexanderDerck for your help.

更多推荐

不可报告成员'File'不能像生成报告时那样使用

本文发布于:2023-06-10 05:47:05,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/608264.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:报告   能像   成员   File

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!