zoukankan      html  css  js  c++  java
  • .Net文档下载

     1 public static void DownLoadFile(string fileName, HttpResponse Response, HttpServerUtility Server)
     2     {
     3         string path = Server.MapPath("~/UpFiles/" + fileName);
     4         FileInfo fileInfo = new FileInfo(path);
     5 
     6         //TextWriter writer = new StreamWriter(defultPath);
     7         //HttpResponse Response = new HttpResponse(writer);
     8 
     9         Response.Clear();
    10 
    11         Response.ClearContent();
    12 
    13         Response.ClearHeaders();
    14 
    15         Response.AppendHeader("Content-Disposition", "attachment;   filename="" + Server.UrlEncode(fileName) + """);
    16 
    17         Response.AddHeader("Content-Length", fileInfo.Length.ToString());
    18 
    19         Response.AddHeader("Content-Transfer-Encoding", "binary");
    20 
    21         Response.ContentType = "application/octet-stream";
    22 
    23         Response.ContentEncoding = System.Text.Encoding.UTF8;
    24 
    25         Response.WriteFile(fileInfo.FullName);
    26 
    27         Response.Flush();
    28 
    29         Response.End();
    30     }
    View Code


    已有文档下载。

    防中文乱码:Server.UrlEncode(fileName)

  • 相关阅读:
    es6简述
    vue梳理
    webpack常用插件
    JS知识点
    CSS知识点
    224646
    223301
    图书馆 摘 1
    消息队列高手课 笔记6
    消息队列高手课 笔记5
  • 原文地址:https://www.cnblogs.com/senyier/p/3498559.html
Copyright © 2011-2022 走看看