byte
[] file = (
byte
[])ds.Tables[0].Rows[0][
"FContent"
];
string
Type = checktype(docName);
Response.AddHeader(
"Content-Disposition"
,
"attachment;filename="
+ HttpUtility.UrlEncode(docName, System.Text.Encoding.UTF8).Replace(
"+"
,
"%20"
));
Response.AddHeader(
"Content-Length "
, file.Length.ToString());
Response.ContentType = Type;
Response.BinaryWrite(file);
Response.End();
Response.Clear();
/// <summary>
/// 根据文件的扩展名来获取对应的“输出流的HTTP MIME“类型
/// </summary>
/// <param name="filename"></param>
/// <returns></returns>
private
string
checktype(
string
filename)
{
string
ContentType;
switch
(filename.Substring(filename.LastIndexOf(
"."
)).Trim().ToLower())
{
case
".asf "
:
ContentType =
"video/x-ms-asf "
;
break
;
case
".avi "
:
ContentType =
"video/avi "
;
break
;
case
".doc "
:
ContentType =
"application/msword "
;
break
;
case
".zip "
:
ContentType =
"application/zip "
;
break
;
case
".xls "
:
ContentType =
"application/vnd.ms-excel "
;
break
;
case
".gif "
:
ContentType =
"image/gif "
;
break
;
case
".jpg "
:
ContentType =
"image/jpeg "
;
break
;
case
"jpeg "
:
ContentType =
"image/jpeg "
;
break
;
case
".wav "
:
ContentType =
"audio/wav "
;
break
;
case
".mp3 "
:
ContentType =
"audio/mpeg3 "
;
break
;
case
".mpg "
:
ContentType =
"video/mpeg "
;
break
;
case
".mepg "
:
ContentType =
"video/mpeg "
;
break
;
case
".rtf "
:
ContentType =
"application/rtf "
;
break
;
case
".html "
:
ContentType =
"text/html "
;
break
;
case
".htm "
:
ContentType =
"text/html "
;
break
;
case
".txt "
:
ContentType =
"text/plain "
;
break
;
default
:
ContentType =
"application/octet-stream "
;
break
;
}
return
ContentType;
}