zoukankan      html  css  js  c++  java
  • Asp.Net下载页面,并弹出下载提示框

    Asp.Net下载页面,并弹出下载提示框.在删除按钮里调用以下方法.

        /// <summary>
        /// 指定要下载文件的虚拟路径及文件名
        /// </summary>
        /// <param name="FileName"></param>
        public void downloadfile(string FileName)
        {
    
              //打开要下载的文件 
              System.IO.FileStream r = new System.IO.FileStream(Server.MapPath(FileName), System.IO.FileMode.Open); 
              //设置基本信息 
              Response.Buffer = false; 
              Response.AddHeader("Connection", "Keep-Alive"); 
              Response.ContentType = "application/octet-stream"; 
              Response.AddHeader("Content-Disposition", "attachment;filename=" + System.IO.Path.GetFileName(FileName)); 
              Response.AddHeader("Content-Length", r.Length.ToString()); 
    
    
              while (true) 
              { 
                  //开辟缓冲区空间 
                  byte[] buffer = new byte[1024]; 
                  //读取文件的数据 
                  int leng = r.Read(buffer, 0, 1024); 
                  if (leng == 0)//到文件尾,结束 
                      break; 
                  if (leng == 1024)//读出的文件数据长度等于缓冲区长度,直接将缓冲区数据写入 
                      Response.BinaryWrite(buffer); 
                  else 
                  { 
                      //读出文件数据比缓冲区小,重新定义缓冲区大小,只用于读取文件的最后一个数据块 
                      byte[] b = new byte[leng]; 
                      for (int i = 0; i < leng; i++) 
                      b[i] = buffer[i]; 
                      Response.BinaryWrite(b); 
                  } 
              } 
              r.Close();//关闭下载文件 
              Response.End();//结束文件下载 
        }

  • 相关阅读:
    Apache服务器的简单配置与安全策略
    Linux下的ICMP反弹后门:PRISM
    项目年度任务失败总结
    SpringBoot下配置Druid
    ftm国际化解决方案
    SpringBoot自动装配源码解析
    log4j到log4j2升级迁移方案
    Linux常用命令记录
    MySQL安装后无法用root用户访问的问题
    html实体命名
  • 原文地址:https://www.cnblogs.com/xieon1986/p/3447507.html
Copyright © 2011-2022 走看看