当前位置:跳过导航链接计算机毕业设计首页 : 技术应用 : 详细内容

ASP.NET实现打开下载对话框

来源:本站原创 作者:管理员 添加时间:2011-08-17 点击数:1335

  在网上会经常看到点击某个下载文件时,会弹出“下载”提示框,提示框里包括:打开、保存、取消的选项,那么如何利用asp.net语言实现这个功能呢?下面把代码贡献如下:

  asp.net下载文件 ///

 
  /// 下载文件 
  ///
 
  /// 文件路径(绝对路径) 
  public static void DownloadData(string path) 
  { 
  if (File.Exists(path)) 
  { 
  FileInfo DownloadFile = new FileInfo(path); 
  System.Web.HttpContext.Current.Response.Clear(); 
  System.Web.HttpContext.Current.Response.ClearHeaders(); 
  System.Web.HttpContext.Current.Response.Buffer = false; 
  System.Web.HttpContext.Current.Response.ContentType = "application/octet-stream"; 
  System.Web.HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(DownloadFile.FullName, System.Text.Encoding.UTF8)); 
  System.Web.HttpContext.Current.Response.AppendHeader("Content-Length", DownloadFile.Length.ToString()); 
  System.Web.HttpContext.Current.Response.WriteFile(DownloadFile.FullName); 
  System.Web.HttpContext.Current.Response.Flush(); 
  System.Web.HttpContext.Current.Response.End(); 
  } 
  else 
  { 
  throw new Exception("提示:下载失败,找不到该文件"); 
  } 
  } 

<责任编辑:计算机毕业设计网(http://www.xiaoniu168.com)>

第1页

【联系方式】

【本站信誉】

用心做计算机毕业设计论文网