本文转自: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 文本下载的更多相关文章

  1. C#中解决Response.AddHeader("Content-Disposition", "attachment; filename=" + filename)下载文件时文件名乱码的问题

    问题:下载文件时文件名乱码怎么解决? 在C#写后台代码过程中,经常遇到下载文件出现文件名乱码的问题,在网上找了很多方法,总是存在浏览器不兼容的问题,当IE浏览器不乱码时,火狐浏览器就会乱码,后来经过反 ...

  2. 关于使用response.addHeader下载中文名乱码问题

    介绍下我项目中遇到的问题:在数据库导出Excel文件的过程中,导出文件中文名始终异常,最终结果发现需要在response.addHeader 中的 filename = "xxxx" ...

  3. 转(Response.WriteFile 无法下载大文件解决方法)

    以前用Response.WriteFile(filename),但当遇到大文件时无法完整下载. 该方法最大的问题,它不是直接将数据抛到客户端,而是在服务器端(IIS)上缓存.当下载文件比较大时,服务器 ...

  4. Response.AddHeader使用实例

    1.文件下载,指定默认名Response.AddHeader("content-type","application/x-msdownload"); // 限制 ...

  5. Response.AddHeader小结

    (一)文件下载,指定默认名 Response.AddHeader("content-type","application/x-msdownload"); Res ...

  6. Response.AddHeader

    Response.AddHeader使用实例 1.文件下载,指定默认名 Response.AddHeader("content-type","application/x- ...

  7. .net中 登录 才能下载文件的方法 Response.WriteFile实现下载

    protected void Button2_Click(object sender, EventArgs e) { //可以在这里加是否登录的判断 string fileName = "c ...

  8. 解决Response.AddHeader中文乱码问题

    string filename = HttpUtility.UrlEncode(Encoding.UTF8.GetBytes("培训班自然情况表")); Response.AddH ...

  9. [javaEE] response实现图片下载

    在Servlet中的doGet()方法中 获取FileInputStream对象,new出来,构造参数:String的文件路径 得到文件路径,调用this.getServletContext().ge ...

随机推荐

  1. ES6学习小计

    1.增加了for of语法,对应C#里的foreach,注意ES5中的 for in只会传递0,1,2.....序号,并且是字符for-of循环语句通过方法调用来遍历各种集合.数组.Maps对象.Se ...

  2. homework-01 最大子串和

    题目描述 对于一个给定的数列,求该数列最大的子串和(连续) 问题分析 处理发生区间上的问题时,经常会用一个非常简单经典的思路——部分和(也有叫前缀和).部分和的思想在很多复杂的区间上的算法中都有应用, ...

  3. Linux 命令之last命令详解

    last:命令解释show listing of last logged in users 指令所在路径:/usr/bin/last 命令输出字段介绍: 第一列:用户名 第二列:终端位置.pts/0 ...

  4. Spring SimpleJdbcTemplate batchUpdate() example

    In this tutorial, we show you how to use batchUpdate() in SimpleJdbcTemplate class. See batchUpdate( ...

  5. codeforce 621A(水题)

    A. Wet Shark and Odd and Even time limit per test 2 seconds memory limit per test 256 megabytes inpu ...

  6. [iOS微博项目 - 1.6] - 自定义TabBar

    A.自定义TabBar 1.需求 控制TabBar内的item的文本颜色(普通状态.被选中状态要和图标一致).背景(普通状态.被选中状态均为透明) 重新设置TabBar内的item位置,为下一步在Ta ...

  7. C#中的表达式树简介

    表达式树是.NET 3.5之后引入的,它是一个强大灵活的工具(比如用在LINQ中构造动态查询). 先来看看Expression类的API接口: using System.Collections.Obj ...

  8. MSXML读取XML中文

    // QueryNodes.cpp : Defines the entry point for the console application. // #include <stdio.h> ...

  9. rqnoj-105-核电站问题-dp

    刚刚发现一个问题..原来这个oj叫rqnoj不是rnqoj... 简单的状态转换~~ #include<stdio.h> #include<string.h> #include ...

  10. Codeforces Round #337 (Div. 2) D. Vika and Segments (线段树+扫描线+离散化)

    题目链接:http://codeforces.com/contest/610/problem/D 就是给你宽度为1的n个线段,然你求总共有多少单位的长度. 相当于用线段树求面积并,只不过宽为1,注意y ...