您的位置:首页 > 编程语言 > ASP

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',
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  asp.net xhtml rtf xsl string exe