[转]Response.AddHeader 文本下载
本文转自:http://hi.baidu.com/yuxi981/item/7c617fc41b03ad60f6c95d30
Response.AddHeader实现下载 /// <summary>
///
Response.AddHeader实现下载
/// </summary>
/// <param
name="filePath">完整的文件路径</param>
/// <param
name="fileName">文件名</param>
private void DownFile(string
filePath, string fileName)
{
FileInfo fileInfo = new
FileInfo(filePath);
Response.Clear();
Response.ClearContent();
Response.ClearHeaders();
Response.AddHeader("Content-Disposition", "attachment;filename=" +
fileName);
Response.AddHeader("Content-Length",
fileInfo.Length.ToString());
Response.AddHeader("Content-Transfer-Encoding", "binary");
Response.ContentType = "application/octet-stream";
Response.ContentEncoding =
System.Text.Encoding.GetEncoding("gb2312");
Response.WriteFile(fileInfo.FullName);
Response.Flush();
Response.End();
}下面才是我实际用的下载代码,好象对中文名的支持还可以,呵呵,我对网络上的各种编码不熟悉,可能只是走运吧,希望能帮大家解决一些问题,我的这些都是看了尚俊杰先生的ASP
无组件上传原理简明教程 后学会的,大家可以到网上查查看<%
if request("id") ="" then
response.End()
Set conn=Server.CreateObject("ADODB.Connection")
conn.Open
mallDSN
strSql="Select * From files where id = " & Request("id")
Set
rs=conn.Execute(strSql)
if conn.errors.count >0 then
response.write("数据库错误!不能下载!")
end if
Response.Buffer = true
Response.Clear
Select Case lcase(rs("contentType"))
Case
".asf"
ContentType = "video/x-ms-asf"
Case ".avi"
ContentType =
"video/avi"
Case ".doc"
ContentType = "application/msword"
Case
".zip"
ContentType = "application/zip"
Case ".xls"
ContentType =
"application/vnd.ms-excel"
Case ".gif"
ContentType = "image/gif"
Case ".jpg", "jpeg"
ContentType = "image/jpeg"
Case ".wav"
ContentType = "audio/wav"
Case ".mp3"
ContentType = "audio/mpeg3"
Case ".mpg", "mpeg"
ContentType = "video/mpeg"
Case ".rtf"
ContentType = "application/rtf"
Case ".htm", "html"
ContentType =
"text/html"
Case ".txt"
ContentType = "text/plain"
Case Else
ContentType = "application/octet-stream"
End Select
'Response.Charset = "UTF-8"
'下面将文件输出到客户端,首先指明
ContentType,其实这里用下面两行哪个都可以
Response.ContentType =
ContentType
'Response.ContentType = rs("contentType")
'告诉浏览器文件名称
Response.AddHeader "Content-Disposition","attachment;filename=" &
rs("filename")
'告诉浏览器文件大小
Response.AddHeader "Content-Length",
CStr(rs("size"))
'输出二进制文件
Response.BinaryWrite rs("fileimage")
Response.Flush
response.Clear()
%>
[转]Response.AddHeader 文本下载的更多相关文章
- C#中解决Response.AddHeader("Content-Disposition", "attachment; filename=" + filename)下载文件时文件名乱码的问题
问题:下载文件时文件名乱码怎么解决? 在C#写后台代码过程中,经常遇到下载文件出现文件名乱码的问题,在网上找了很多方法,总是存在浏览器不兼容的问题,当IE浏览器不乱码时,火狐浏览器就会乱码,后来经过反 ...
- 关于使用response.addHeader下载中文名乱码问题
介绍下我项目中遇到的问题:在数据库导出Excel文件的过程中,导出文件中文名始终异常,最终结果发现需要在response.addHeader 中的 filename = "xxxx" ...
- 转(Response.WriteFile 无法下载大文件解决方法)
以前用Response.WriteFile(filename),但当遇到大文件时无法完整下载. 该方法最大的问题,它不是直接将数据抛到客户端,而是在服务器端(IIS)上缓存.当下载文件比较大时,服务器 ...
- Response.AddHeader使用实例
1.文件下载,指定默认名Response.AddHeader("content-type","application/x-msdownload"); // 限制 ...
- Response.AddHeader小结
(一)文件下载,指定默认名 Response.AddHeader("content-type","application/x-msdownload"); Res ...
- Response.AddHeader
Response.AddHeader使用实例 1.文件下载,指定默认名 Response.AddHeader("content-type","application/x- ...
- .net中 登录 才能下载文件的方法 Response.WriteFile实现下载
protected void Button2_Click(object sender, EventArgs e) { //可以在这里加是否登录的判断 string fileName = "c ...
- 解决Response.AddHeader中文乱码问题
string filename = HttpUtility.UrlEncode(Encoding.UTF8.GetBytes("培训班自然情况表")); Response.AddH ...
- [javaEE] response实现图片下载
在Servlet中的doGet()方法中 获取FileInputStream对象,new出来,构造参数:String的文件路径 得到文件路径,调用this.getServletContext().ge ...
随机推荐
- Centos6.4 coll linux 10.2
由于oracle10g太老了,只怪他娘Oracle生它生的太早了,差点就没赶上新时代(这家伙内心可也有些挺自豪的东东的,人家很有可能跟着它的主要干爹工程师为雅典奥运贡献了门票哩,生逢盛会啊!),较Ce ...
- 转】Maven学习总结(二)——Maven项目构建过程练习
原博文出自于:http://www.cnblogs.com/xdp-gacl/p/4051690.html 感谢! 上一篇只是简单介绍了一下maven入门的一些相关知识,这一篇主要是体验一下Maven ...
- 在C++中定义常量的两种方法的比较
常量是定以后,在程序运行中不能被改变的标识符.C++中定义常量可以用#define .const 这两种方法.例如:#define PRICE 10 //定义单价常量10const int PRICE ...
- HDU 2647 Reward (拓扑排序)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2647 题意是给你n点m条有向边,叶子点(出度为0)上的值为888,父亲点为888+1,依次计算... ...
- poj3259
Wormholes Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 24864 Accepted: 8869 Descri ...
- TypeScript学习笔记(一):介绍及环境搭建
官网 TypeScript目前还在快速的发展中,当前的版本是1.6,有关TypeScript更多的信息可以在其官网中获取. http://www.typescriptlang.org/ 什么是Type ...
- WordPress 主题框架是如何工作的
主题框架可以说是无比强大的!对于非技术型的 WordPress 用户来说,主题框架使得建立一个独一无二并看起来像是运行一个量身定制的主题的网站成为可能,并且对于 WordPress 开发者来说,它们能 ...
- 在WinForm中使用Web Service来实现软件自动升级
来源:互联网 winform程序相对web程序而言,功能更强大编程更方便,但软件更新却相当麻烦,要到客户端一台一台地升级,面对这个实际问题,在最近的一个小项目中,本人设计了一个通过软件实现自动升级技术 ...
- CF:322D - Ciel and Duel 贪心 或者 DP 我用的贪心 。。难道sort跟qsort是不一样的么?
D. Ciel and Duel time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...
- andriod开发,简单的封装网络请求并监听返回.
一.为什么封装 因为android 4.0 以后的发送网络请求必须要放到异步线程中,而异步线程必须跟handle合作才能更新主线程中的UI,所以建议用一个类继承handler来异步处理网络请求. 二. ...