MVC下载文件方式
来源:互联网 发布:淘宝新手卖家 编辑:程序博客网 时间:2024/05/21 14:56
方式一:
public FileStreamResult DownFile(string filePath, string fileName) { string absoluFilePath = Server.MapPath(System.Configuration.ConfigurationManager.AppSettings["AttachmentPath"] + filePath); return File(new FileStream(absoluFilePath, FileMode.Open), "application/octet-stream", Server.UrlEncode(fileName)); }
方式二:
public ActionResult DownFile(string filePath, string fileName) { filePath = Server.MapPath(System.Configuration.ConfigurationManager.AppSettings["AttachmentPath"] + filePath); FileStream fs = new FileStream(filePath, FileMode.Open); byte[] bytes = new byte[(int)fs.Length]; fs.Read(bytes, 0, bytes.Length); fs.Close(); Response.Charset = "UTF-8"; Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8"); Response.ContentType = "application/octet-stream"; Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(fileName)); Response.BinaryWrite(bytes); Response.Flush(); Response.End(); return new EmptyResult(); }
View调用:
<a href="/Document/DownFile?filePath=@item.Value&fileName=@item.Key">下载</a>
- MVC下载文件方式
- MVC下载文件方式
- MVC下载文件方式
- MVC下载文件方式
- MVC下载文件方式
- MVC 下载文件的方式
- Spring MVC - 两种文件下载方式
- 文件的上传与下载之方式3:Spring MVC
- mvc 下载文件
- Spring MVC 文件下载
- Spring mvc 文件下载
- spring mvc 文件下载
- Spring MVC下载文件
- MVC 文件下载
- spring mvc 文件下载
- Spring mvc 文件下载
- mvc文件下载实例
- Spring MVC文件下载
- 各种编码方式
- Javascript的执行过程详细研究
- 怎么样安装arm-linux-gcc
- threadpool
- .NET 的绘图控件ZedGraph
- MVC下载文件方式
- 交换机的基本配置
- SAP宣布58亿美元收购Sybase移动平台和数据库业务
- 根据汇报获取某个职位的上级职位
- Centos6 安装 gnome桌面
- java继承并重写方法时抛出一样的异常或不抛异常,既不能多也不能少,范围既不能打也不能小
- linux fork 函数解析
- Mina入门:Java NIO框架Mina、Netty、Grizzly介绍与对比
- AAA与Radius