ASP.NET实现文件下载
2014-02-16 21:36
141 查看
转:http://blog.csdn.net/codeshark/article/details/2473664
方式一:TransmitFile实现下载。将指定的文件直接写入 HTTP 响应输出流,而不在内存中缓冲该文件。
protected void Button1_Click(object sender, EventArgs e)
protected void Button2_Click(object[b] sender, EventArgs e)
protected void Button3_Click(object sender, EventArgs e)
protected void Button4_Click(object sender, EventArgs e)
{
string fileName = "CodeShark.zip";//客户端保存的文件名
string filePath = Server.MapPath("DownLoad/CodeShark.zip");//路径
//以字符流的形式下载文件
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();
}
方式一:TransmitFile实现下载。将指定的文件直接写入 HTTP 响应输出流,而不在内存中缓冲该文件。
protected void Button1_Click(object sender, EventArgs e)
protected void Button2_Click(object[b] sender, EventArgs e)
protected void Button3_Click(object sender, EventArgs e)
protected void Button4_Click(object sender, EventArgs e)
{
string fileName = "CodeShark.zip";//客户端保存的文件名
string filePath = Server.MapPath("DownLoad/CodeShark.zip");//路径
//以字符流的形式下载文件
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 2.0 HttpHandler实现对某种文件类型权限保护(示例代码下载)
- ASP.NET中实现直接从网页上下载文件
- Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)
- Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)
- Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)
- ASP.NET中下载文件的实现
- 使用JS实现文件下载示例(asp.net)
- 在asp.net实现文件下载
- Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)
- ASP.NET 2.0 HttpHandler实现对某种文件类型权限保护(示例代码下载)
- ASP.NET实现从服务器下载文件问题处理
- asp.net中下载文件的实现方法
- asp.net实现文件下载的代码
- iOS开发之结合asp.net webservice实现文件上传下载
- 解决Asp.net 实现文件下载时、输出文件时文件名的中文乱码和空格异常
- [导入]Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)
- ASP.NET中实现文件下载功能
- ASP.NET实现文件的上传与下载(包括用数据库存取文件)
- ASP.NET 实现PDF文件下载