• ASP.NET实现文件的下载


    ASP.NET实现文件下载功能

     关键代码

    protected void btnDownFile_Click(object sender, EventArgs e)
        {
            try
            {
              string filePath = Server.MapPath("汪苏泷 - 苦笑.mp3");//得到下载文件物理地址
                string fileName = Path.GetFileName(filePath);//得到下载文件的文件名
                Response.Clear();//清空文件流
                //设置输出文件格式
                Response.ContentType = "application/octet-stream";
                //在下载头文件中设置下载名称
                Response.AddHeader("Content-Disposition", "attachment;filename=" + fileName);
                Response.Flush();
                Response.WriteFile(filePath);//下载文件
            }
            catch (Exception ex)
            {
    
                Response.Write(ex.Message);
            }
        }
  • 相关阅读:
    虚继承virtual public
    My first blog
    mybatis(一)SqlSessionFactory初始化
    dubbo
    设计模式
    基本算法
    redis
    spring cloud eureka
    spring boot
    spring MVC
  • 原文地址:https://www.cnblogs.com/luodao1991/p/3032794.html
Copyright © 2020-2023  润新知