zoukankan      html  css  js  c++  java
  • 关于asp.net文件下载基本操作

     protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                int id=int.Parse(Request.QueryString["id"]); //页数传过来的id
                getdownloadFilePath(id);
            }
        }


        public void getdownloadFilePath(int id)
        {
            string sqlTable = " download where DownloadID=" + id;//到下载中表去找对应的文件名
            DataSet ds = clsMySql.GetDataTable(sqlTable);
            string fileName = ds.Tables[0].Rows[0]["DownloadFile"].ToString();//取数据库文件名
            string path = Server.MapPath("./download/")+fileName;//得到映射路径
            Response.Write(path);//测试一下

            //以下是简单的下载方法,有很多地方可以完善!!
            System.IO.FileInfo theFile = new System.IO.FileInfo(path);
            Response.Clear();
            Response.AddHeader("Content-Disposition", "attachment; filename=" + theFile.Name);
            Response.AddHeader("Content-Length", theFile.Length.ToString());
            Response.ContentType = "application/octet-stream";
            Response.WriteFile(theFile.FullName);
            Response.End();

        }

  • 相关阅读:
    【SpringBoot系列】邮件发送
    【问题】InteliJ IDEA生成可执行jar运行提示没有主清单属性
    【设计模式】单例设计模式
    【C3P0】C3P0
    【JDBC】JDBC学习(一)
    react hook 防抖
    主线程 宏任务 微任务
    vue 2.0 渲染dom过程
    源码阅读笔记,杂乱
    vue 3.0 响应式原理
  • 原文地址:https://www.cnblogs.com/yzenet/p/2303801.html
Copyright © 2011-2022 走看看