• 项目--下载文件


    /// <summary>
            /// 下载文件
            /// </summary>
            /// <param name="FullFileName"></param>
            public static void FileDownload(string FullFileName)
            {
                FileInfo DownloadFile = new FileInfo(FullFileName); //设置要下载的文件
              
                 HttpContext.Current.Response.Clear(); //清除缓冲区流中的所有内容输出
                 HttpContext.Current.Response.ClearHeaders(); //清除缓冲区流中的所有头
                 HttpContext.Current.Response.Buffer = false; //设置缓冲输出为false
                //设置输出流的 HTTP MIME 类型为application/octet-stream
                 HttpContext.Current.Response.ContentType = "application/octet-stream";
                //将 HTTP 头添加到输出流
                string s = HttpUtility.UrlEncode(System.Text.UTF8Encoding.UTF8.GetBytes(DownloadFile.Name));
                HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + s);// HttpUtility.UrlEncode(DownloadFile.Name, System.Text.Encoding.UTF8));
    
                HttpContext.Current.Response.AppendHeader("Content-Length", DownloadFile.Length.ToString());
    
                //将指定的文件直接写入 HTTP 内容输出流。
    
                HttpContext.Current.Response.WriteFile(DownloadFile.FullName);
                HttpContext.Current.Response.Flush(); //向客户端发送当前所有缓冲的输出
                HttpContext.Current.Response.End(); //将当前所有缓冲的输出发送到客户端
    
            }

    调用代码:

    string path = "/UploadFile/Template/ImportApplyInfo.xlsx";//目录为当前web下目录
    FileDownload(this.Server.MapPath(path));
  • 相关阅读:
    实验17:NAT
    实验16:ACL
    实验15: STP
    实验14:VLAN间的路由
    实验13:VLAN/TRUNK/VTP/
    Linux软件管理--RPM工具
    Linux拓展练习部分--输入输出 / find部分 /基础拓展2
    linux文件管理--压缩打包
    find 文件查找
    防火墙知识点
  • 原文地址:https://www.cnblogs.com/buzi521/p/3875040.html
Copyright © 2020-2023  润新知