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)

  • 相关阅读:
    jmeter取样器
    【递归】普通递归关系
    7月,开始奋斗吧!
    BZOJ 1503 郁闷的出纳员
    bzoj 3262: 陌上花开
    BZOJ 2286 消耗战
    莫队
    bzoj1483: [HNOI2009]梦幻布丁
    字符串算法模板
    高级数据结构模板
  • 原文地址:https://www.cnblogs.com/senyier/p/3498559.html
Copyright © 2011-2022 走看看