asp.net 文件下载
来源:互联网 发布:大数据存储详解 编辑:程序博客网 时间:2024/05/14 04:58
asp.net 文件下载:
protected void down_Click(object sender, EventArgs e) { string fileName = "图片悬停.rar";//客户端保存的文件名 string filePath = Server.MapPath("file/图片悬停.rar");//路径 //以字符流的形式下载文件 FileStream fs = new FileStream(filePath, FileMode.Open); byte[] bytes = new byte[(int)fs.Length]; fs.Read(bytes, 0, bytes.Length); fs.Close(); Response.ContentType = "application/octet-stream"; //通知浏览器下载文件而不是打开 Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8)); Response.BinaryWrite(bytes); Response.Flush(); Response.End(); }
asp.net mvc文件下载:
public ActionResult FileDown() { //byte[] content=System.IO.File.ReadAllBytes(Server.MapPath("/file/ASP.NET MVC4开发指南.pdf")); // Stream ftpStream = System.IO.File.Open(Server.MapPath("/file/ASP.NET MVC4开发指南.pdf"),FileMode.Open); //return File(ftpStream, System.Net.Mime.MediaTypeNames.Application.Octet, "MVC4开发指南.pdf"); if (!System.IO.File.Exists(Server.MapPath("/file/sql.txt"))) { return JavaScript("<script>alert('文件不存在!')</script>"); ; } var fs =System.IO.File.Open(Server.MapPath("/file/sql.txt"), FileMode.Open) ; var bytes = new byte[(int)fs.Length]; fs.Read(bytes, 0, bytes.Length); fs.Close(); return File(bytes, "application/octet-stream", "sql语句.txt"); }
asp.net mvc后台返回图片:
public ActionResult Index() { //Uri url = Request.UrlReferrer; byte[] data = System.IO.File.ReadAllBytes(Server.MapPath("/Images/heroAccent.png")); //return File(data, @"image/jpeg", "heroAccent.png"); return File(data, @"image/jpeg"); }
0 0
- 下载文件 asp.net
- ASP.NET文件下载
- asp.net 文件下载
- asp.net 下载文件
- Asp.net 下载文件
- asp.net文件下载
- Asp.net 文件下载
- ASP.NET 文件下载
- ASP.NET 下载文件
- asp.net下载文件
- Asp.Net 文件下载
- ASP.NET 文件下载
- ASP.NET下载文件
- ASP.NET下载文件
- asp.net下载文件
- ASP.NET文件下载
- asp.net下载文件
- ASP.NET 文件下载
- 软件开发模型
- 《PCI EXPRESS体系结构导读》读书笔记之PCI-X总线简介
- Testlink用后感触
- Deep Sparse Rectifier Neural Networks(阅读)
- hdu2191 多重背包问题
- asp.net 文件下载
- 关于iPhone 6S你想知道的一切
- 应用程序无法正常启动0xc000007b
- JNI编程指南-第二章 开始(HelloWorld)
- Android NDK学习 <二> Android.mk的制作
- Yii rules常用规则
- 关于宽字节和多字节之间的转换
- 独立博客免费图床的选择
- [翻译]大数据处理的趋势-五种开源技术介绍