zoukankan      html  css  js  c++  java
  • C#文件流下载文件

    1,推荐指数*****,大文件也可以

    string fileName = "test.pdf";
    string filePath = Server.MapPath("/" + fileName);
    Response.ContentType = "application/octet-stream";
    Response.AddHeader("Content-Disposition", "attachment;filename=" + fileName);
    Response.TransmitFile(filePath);

    2,推荐指数****

    string fileName = "test.pdf";
    string filePath = Server.MapPath("/" + fileName);
    FileInfo fileInfo = new FileInfo(filePath);
    Response.Clear(); Response.ClearContent(); Response.ClearHeaders(); Response.AddHeader("Content-Disposition", "attachment;filename=" + fileName); Response.AddHeader("Content-Length", fileInfo.Length.ToString());
    Response.AddHeader(
    "Content-Transfer-Encoding", "binary"); Response.ContentType = "application/octet-stream";//application//pdf Response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8"); Response.WriteFile(fileInfo.FullName); Response.Flush(); Response.End();

    3、推荐指数***,大于400m的文件会卡死

    string fileName = "test.pdf";
            string filePath = Server.MapPath("/" + fileName);
    
            FileStream fs = new FileStream(filePath, FileMode.Open);
            byte[] bytes = new byte[(int)fs.Length];
            fs.Read(bytes, 0, bytes.Length);
            fs.Close();
            Response.ContentType = "application/octet-stream";
            Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
            Response.BinaryWrite(bytes);
            Response.Flush();
            Response.End();

    //成功一定有方法,失败一定有原因。
  • 相关阅读:
    Linux下处理文件中的^M
    python selenium-webdriver 生成测试报告 (十四)
    Apache 配置Https 转发Tomcat Http
    自动化测试神器 之 python unittest 断言
    创建高性能索引笔记
    【转】正向代理vs反向代理
    vue 常用问题
    eslint 代码规范2
    WebStrom2018注册码
    Vue-selller 饿了吗
  • 原文地址:https://www.cnblogs.com/webapi/p/15146515.html
Copyright © 2011-2022 走看看