zoukankan      html  css  js  c++  java
  • Ext.Net中,文件下载。

    传参到另一个页面(~/Service/DownLoad.aspx)

     /// <summary>
        /// 下载附件按钮事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void lbnDownloadWork_Click(object sender, EventArgs e)
        {
            try
            {
                int pid = Convert.ToInt32(Request.QueryString["pid"]);
                MC_WORK_TASKACCESSORY GetAcessoryInfo = TaskService.GetTaskAcessoryByID(pid);
                string name = GetAcessoryInfo.DESCRIPTION;
                string Path = GetAcessoryInfo.ACCESSORYURL;
    
                string fileName = name;//客户端保存的文件名 
                string filePath = Server.MapPath(Path);//路径
    
                X.Redirect("~/Service/DownLoad.aspx?filename=" + fileName + "&filepath=" + filePath); 
            }
            catch
            {
                //提示信息:文件下载失败
                X.Msg.Alert("提示信息", "附件下载失败!").Show();
            }
        }
     protected void Page_Load(object sender, EventArgs e)
        {
            string filename = Request.QueryString["filename"];
            string filepath = Request.QueryString["filepath"];
            DownloadFile(filename, filepath);
        }
    
        /// <summary>
        /// 文件下载
        /// </summary>
        /// <param name="filename">文件名</param>
        /// <param name="filepath">文件路径</param>
        protected void DownloadFile(string filename, string filepath)
        {
            Response.Clear();
            Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(filename, System.Text.Encoding.Default));
            Response.ContentType = "application/octet-stream";
            Response.TransmitFile(filepath);
            Response.End();
        }
  • 相关阅读:
    PHP实现邮件的自动发送
    为PostgreSQL的表自动添加分区
    django
    django的logging模块
    job
    python 类的方法带的self理解
    java
    choice_set的理解
    django
    proxy_next_upstream带来的坑和加载sticky模块
  • 原文地址:https://www.cnblogs.com/chenhaibo/p/3081237.html
Copyright © 2011-2022 走看看