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();
                }
            }
  • 相关阅读:
    声明、定义本质的区别:有无内存的分配
    typedef 与 define 的区别
    Linux内核中链表的学习
    C语言数据类型的转换
    状态机
    170311php添加留言页面
    170314网络编程之TCP聊天窗口
    php课堂2简单作业+文件上传之案例
    php案例2——用户列表页
    学生管理系统
  • 原文地址:https://www.cnblogs.com/malianyong/p/2866646.html
Copyright © 2011-2022 走看看