asp.net – Web窗体中的.NET MVC FileResult等价物
发布时间:2020-12-15 23:55:42 所属栏目:asp.Net 来源:网络整理
导读:我正在使用FileResult作为MVC中返回PDF文件的函数的返回值. 我应该在Web窗体中使用什么返回类型? 谢谢 public FileResult PrintPDFVoucher(object sender,EventArgs e) { PdfDocument outputDoc = new PdfDocument(); PdfDocument pdfDoc = PdfReader.Open(
我正在使用FileResult作为MVC中返回PDF文件的函数的返回值.
我应该在Web窗体中使用什么返回类型? 谢谢 public FileResult PrintPDFVoucher(object sender,EventArgs e) { PdfDocument outputDoc = new PdfDocument(); PdfDocument pdfDoc = PdfReader.Open( Server.MapPath(ConfigurationManager.AppSettings["Template"]),PdfDocumentOpenMode.Import ); MemoryStream memory = new MemoryStream(); try { //Add pages to the import document int pageCount = pdfDoc.PageCount; for (int i = 0; i < pageCount; i++) { PdfPage page = pdfDoc.Pages[i]; outputDoc.AddPage(page); } //Target specifix page PdfPage pdfPage = outputDoc.Pages[0]; XGraphics gfxs = XGraphics.FromPdfPage(pdfPage); XFont bodyFont = new XFont("Arial",10,XFontStyle.Regular); //Save outputDoc.Save(memory,true); gfxs.Dispose(); pdfPage.Close(); } finally { outputDoc.Close(); outputDoc.Dispose(); } var result = new FileContentResult(memory.GetBuffer(),"text/pdf"); result.FileDownloadName = "file.pdf"; return result; } 解决方法
在ASP.NET Webforms中,您需要手动将文件写入Response流. webforms中没有结果抽象.
Response.ContentType = "Application/pdf"; //Write the generated file directly to the response stream Response.BinaryWrite(memory);//Response.WriteFile(FilePath); if you have a physical file you want them to download Response.End(); 此代码未经过测试,但这应该可以帮助您完成大方向. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- ASP.NET MVC中的基本认证5
- asp.net-web-api – 是否可以从消息处理程序访问Controller
- C#_.net core 3.0自定义读取.csv文件数据_解决首行不是标题
- asp.net – 当要复制的lob数据的插入长度超过配置的最大值6
- ASP.NET linq选择多个连接
- .net – 我应该如何设计一个允许IoC的类库,但不依赖于特定的
- telerik – Kendo DatePicker对自定义日期格式的验证失败
- 要监控已部署的ASP.NET Web应用程序的关键性能指标是什么?
- 在Build上自动停止/重新启动ASP.NET开发服务器
- asp.net-mvc – 使用jQuery ASP.NET MVC自动保存表单输入
推荐文章
站长推荐
- asp.net-mvc – ASP.NET MVC适合复杂的Web应用程
- asp-classic – 经典的ASP页面是否会运行在Windo
- asp.net-mvc-3 – 发布表单时控件中的模型绑定 –
- asp.net-mvc – Paypal沙箱直接付款内部错误1000
- asp.net-mvc – MVC4 Bootstrap示例中基于角色的
- Pro ASP.NET Core MVC(三)【MVC模式,项目和约定
- asp.net-mvc-4 – 如何在MVC4中删除必需的属性,尽
- ASP.NET Webforms,用户控件中的JavaScript
- ASP.NET Core 2.0 支付宝当面付--扫码支付
- ASP.NET MVC中使用区域时的配置错误4
热点阅读