zoukankan      html  css  js  c++  java
  • 文件下载简单示例

    public void FileDownload2()
    {
    string fileName = "新建文件夹2.rar";//客户端保存的文件名
    string filePath = Server.MapPath("/App_Data/新建文件夹2.rar");//要被下载的文件路径

    Response.ContentType = "application/octet-stream";//二进制流
    //通知浏览器下载文件而不是打开
    Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));

    //以字符流的形式下载文件
    using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read))
    {
    Response.AddHeader("Content-Length", fs.Length.ToString());
    //这里容易内存溢出
    //理论上数组最大长度 int.MaxValue 2147483647
    //(实际分不到这么多,不同的程序能分到值也不同,本人机器,winfrom( 2147483591 相差56)、iis(也差不多2G)、iis Express(只有100多MB))
    byte[] bytes = new byte[(int)fs.Length];
    fs.Read(bytes, 0, bytes.Length);
    Response.BinaryWrite(bytes);
    }
    Response.Flush();
    Response.End();
    }

  • 相关阅读:
    react-native-code-push进阶及实践小结
    Redux 基础
    iOS启动图异常修复方案 -(baidu)
    pod init
    Texture的异步渲染和布局引擎
    iOS 12.1 Tabbar 跳动Bug
    基本绘图的几种方式
    OC 小代码块
    OC基础--类的本质
    OC基础--构造方法 id类型
  • 原文地址:https://www.cnblogs.com/wslpf/p/9502437.html
Copyright © 2011-2022 走看看