zoukankan      html  css  js  c++  java
  • 从以文件流的形式下载文件

    以下代码是把服务器的文件从IE连接上下载到本地,此种方式比直接连接指向服务器文件的方式更安全.

       string strDocPath =  GetFilePath(strPackID, strSuffix, "/ReleaseFile/"); //ReleaseFile指文件所在目录, 需要转换成服务器物理路径.
       if (File.Exists(strDocPath))
       { 
           string strContentType = GetContentType(strSuffix);
           if (strContentType != string.Empty)
            Response.ContentType = strContentType;
        

           Response.Expires = -1;
           Response.Buffer = true;

           Stream fs = File.Open(strDocPath, FileMode.Open, FileAccess.Read);
           BinaryReader Br = new BinaryReader(fs);
           byte[] buffer = new byte[fs.Length];
           Br.Read(buffer, 0, (int)fs.Length);
        //
           Response.AppendHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(strPackName,Encoding.UTF8));
           Response.AppendHeader("content-transfer-encoding", "gb2312");
           Response.AppendHeader("Content-Length", buffer.Length.ToString());
           Response.BinaryWrite(buffer);
           Response.Flush();
           fs.Close();
           Response.End();
    }

  • 相关阅读:
    RDS 工作笔记
    网站测试需要提供的参数和结果分析
    php 安全编程
    留住青春的格子
    保持工作精力旺盛的方法
    百万格子的标签认领可以提高你在alexa的排名的格子
    老电影,似水流年的记忆
    五行 八字 计算
    iis6.0 的 性能比较
    各种情绪和调节方法
  • 原文地址:https://www.cnblogs.com/fbb/p/496987.html
Copyright © 2011-2022 走看看