try
{
string FULLFILENAME = Server.MapPath();
FileInfo downLoadFile = new FileInfo(FULLFILENAME);
if(downLoadFile.Exists)
{
Response.Clear();
Response.ClearHeaders();
Response.Buffer=false;
Response.ContentType="application/octet-stream";
Response.AppendHeader("Content-Disposition","attachment;filename="+HttpUtility.UrlEncode(DownloadFile.FullName,System.Text.Encoding.ASCII));
Response.AppendHeader("Content-Length",DownloadFile.Length.ToString());
Response.WriteFile(DownloadFile.FullName);
Response.Flush();
Response.End();
}
else{
//文件不存在
}
}
catch
{
//文件不存在
}
下面是常用的的ContentType
'doc' => 'application/msword',
'bin' => 'application/octet-stream',
'exe' => 'application/octet-stream',
'class' => 'application/octet-stream',
'dll' => 'application/octet-stream',
'xls' => 'application/vnd.ms-excel',
'ppt' => 'application/vnd.ms-powerpoint',
'vcd' => 'application/x-cdlink',
'dvi' => 'application/x-dvi',
'spl' => 'application/x-futuresplash',
'js' => 'application/x-javascript',
'swf' => 'application/x-shockwave-flash',
'mp2' => 'audio/mpeg',
'mp3' => 'audio/mpeg',
'wav' => 'audio/x-wav',
"wmv" => 'video/x-ms-wmv',
"wma" => 'audio/x-ms-wma',
'pdb' => 'chemical/x-pdb',
'bmp' => 'image/bmp',
'gif' => 'image/gif',
'jpeg' => 'image/jpeg',
'jpg' => 'image/jpeg',
'jpe' => 'image/jpeg',
'png' => 'image/png',
'css' => 'text/css',
'html' => 'text/html',
'htm' => 'text/html',
'asc' => 'text/plain',
'txt' => 'text/plain',
'rtx' => 'text/richtext',
'rtf' => 'text/rtf',
'xsl' => 'text/xml',
'xml' => 'text/xml',
'mpeg' => 'video/mpeg',
'mpg' => 'video/mpeg',
'avi' => 'video/x-msvideo',
'movie' => 'video/x-sgi-movie',