zoukankan      html  css  js  c++  java
  • ASP.NET文件的下载

         /// <summary>
            /// 下载文件
            /// </summary>
            /// <param name="filePath">文件的路径</param>
            /// <param name="fileName">文件名(有时候文件名存在数据库中用于替换路径中的文件名)</param>
            public void FileDownLoad(string filePath, string fileName)
            {
                //判断文件是否存在
                if (System.IO.File.Exists(filePath))
                {
                    FileInfo file = new FileInfo(filePath);
                    Response.Clear();
                    Response.AddHeader("Content-Disposition""attachment; filename=" + Server.UrlEncode(fileName));//解决中文文件名乱码   
                    Response.AddHeader("Content-Length", file.Length.ToString());
                    Response.ContentType = "application/octet-stream";
                    Response.Filter.Close();
                    Response.WriteFile(file.FullName);
                    Response.End();
                }
            }
  • 相关阅读:
    构建之法阅读笔记2
    2020.2.10
    2020.2.9
    2020.2.8
    2020.2.7
    2020.2.6
    2020.2.5
    学习进度——第十三周
    PHPStorm+XAMPP开发php项目
    第一阶段成果建议
  • 原文地址:https://www.cnblogs.com/malianyong/p/2866646.html
Copyright © 2011-2022 走看看