ASP.NET 文件下载功能源码
2011-07-14 17:40
447 查看
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',
'dir' => 'application/x-director',
'dxr' => 'application/x-director',
'dvi' => 'application/x-dvi',
'spl' => 'application/x-futuresplash',
'js' => 'application/x-javascript',
'swf' => 'application/x-shockwave-flash',
'src' => 'application/x-wais-source',
'xhtml' => 'application/xhtml+xml',
'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',
{
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',
'dir' => 'application/x-director',
'dxr' => 'application/x-director',
'dvi' => 'application/x-dvi',
'spl' => 'application/x-futuresplash',
'js' => 'application/x-javascript',
'swf' => 'application/x-shockwave-flash',
'src' => 'application/x-wais-source',
'xhtml' => 'application/xhtml+xml',
'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',
相关文章推荐
- ASP.NET网站文件上传下载功能
- 在ASP.NET中实现压缩多个文件为.zip文件,实现批量下载功能 (转载并优化处理篇)
- 文件的下载(ASP.NET实现邮箱中附件下载的功能)
- Asp.net实现MVC处理文件的上传下载功能实例教程
- Asp.Net Mvc 带进度条大文件上传(附源码下载)
- asp.net中文件下载功能的实例代码
- ASP.NET中实现文件下载功能
- 用jQuery-File-Upload上传Excel文件(ASP.NET MVC)[附源码下载]
- Asp.net 2.0 文件下载[支持多线程, 断点续传功能](示例代码下载)
- Asp.net大文件下载的实现思路及源码
- ASP.NET MVC 向浏览器发送文件以提供文件下载功能
- 【转载】Asp.NET大文件上传组件开发总结_NET2.0源码下载。
- ASP.NET网页中RAR、DOC、PDF等文件下载功能实例源代码
- Asp.net 2.0 文件下载[支持多线程, 断点续传功能](示例代码下载)
- asp.net中实现文件下载功能
- Asp.net 2.0 文件下载[支持多线程, 断点续传功能](示例代码下载)
- asp.net中用FileStream类实现下载文件功能,自定义下载路径,像IE下载一样
- Asp.net(C#)读取数据库并生成JS文件制作首页图片切换效果(附demo源码下载)
- Asp.net 2.0 文件下载[支持多线程, 断点续传功能](示例代码下载)
- 在ASP.NET中支持断点续传下载大文件(ZT)源码