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();
                }
            }
  • 相关阅读:
    字符串
    决策树
    结构体实验
    指针实验
    打印杨辉三角
    P176 1.2.3
    第七次作业
    第六次作业
    第五次作业
    第四次修改
  • 原文地址:https://www.cnblogs.com/malianyong/p/2866646.html
Copyright © 2011-2022 走看看