当前位置导航:炫浪网>>网络学院>>网页制作>>ASP.NET教程

asp.net下载文件

  System.IO.FileInfo file = new System.IO.FileInfo(pstrFilePath);

  if (file.Exists)

  {

  Response.Clear();

  Response.Charset = "GB2312";

  Response.ContentEncoding = System.Text.Encoding.UTF8;

  Response.AddHeader("Content-Disposition", "attachment;filename=" + Server.UrlEncode(file.Name));

  Response.AddHeader("Conten-Length", file.Length.ToString());

  Response.ContentType = "application/ms-excel";

  Response.WriteFile(file.FullName);

  Response.End();

  }

  下面是更详细的ContentType

  'ez' => 'application/andrew-inset',

  'hqx' => 'application/mac-binhex40',

  'cpt' => 'application/mac-compactpro',

  'doc' => 'application/msword',

  'bin' => 'application/octet-stream',

  'dms' => 'application/octet-stream',

  'lha' => 'application/octet-stream',

  'lzh' => 'application/octet-stream',

  'exe' => 'application/octet-stream',

  'class' => 'application/octet-stream',

  'so' => 'application/octet-stream',

  'dll' => 'application/octet-stream',

  'oda' => 'application/oda',

  'pdf' => 'application/pdf',

  'ai' => 'application/postscript',

  'eps' => 'application/postscript',

  'ps' => 'application/postscript',

  'smi' => 'application/smil',

  'smil' => 'application/smil',

  'mif' => 'application/vnd.mif',

  'xls' => 'application/vnd.ms-excel',

  'ppt' => 'application/vnd.ms-powerpoint',

  'wbxml' => 'application/vnd.wap.wbxml',

  'wmlc' => 'application/vnd.wap.wmlc',

  'wmlsc' => 'application/vnd.wap.wmlscriptc',

  'bcpio' => 'application/x-bcpio',

  'vcd' => 'application/x-cdlink',

  'pgn' => 'application/x-chess-pgn',

  'cpio' => 'application/x-cpio',

  'csh' => 'application/x-csh',

  'dcr' => 'application/x-director',

  'dir' => 'application/x-director',

相关内容
赞助商链接