zoukankan      html  css  js  c++  java
  • Ext.Net 实现文件下载

    • 问题描述
         在Ext环境下无法使用传统的.net方式实现文件下载,要么点了下载按钮无反应要么出现乱码。
    • 原因分析
         由于EXT.NET在后台对前台进行操作,依赖的是Extjs,也就是它会向前台输送Javascript脚本代码,如果采用传统的页面内文件下载的方式就会向前台输送一个文件流,那么Extjs就无法正确的识别该文件流,最终导致文件无法下载。
    • 解决方案
         那么怎么才能在Ext环境下实现下载呢?其实很简单,不要在主页面内进行文件下载,而是调用另一个页面专门进行文件下载处理。
      • 主页面
        • 方法一(JS代码)
     window.location.href="~/Service/DownLoad.aspx?filename=" + fileName + "&filepath=" + filePath;
        • 方法二(C#代码)
    X .Redirect("~/Service/DownLoad.aspx?filename=" + fileName + "&filepath=" + filePath); 
      • 下载功能页面
    public partial class Service_DownLoad : System.Web.UI.Page
    {
        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();
        }
    }

     http://www.cnblogs.com/liusuqi/

  • 相关阅读:
    【转】汽车CAN总线
    【转】I2C总线协议
    【转】SPI总线协议
    【转】结构struct 联合Union和枚举Enum的细节讨论
    复合类型变量其首地址的几种表示方式
    【转】四款经典3.7v锂电池充电电路图详解
    【转】crc16几种标准校验算法及c语言代码
    【转】 CRC循环冗余校验码
    对STM32库函数中 assert 函数的认知
    【转】用宏定义代替printf函数
  • 原文地址:https://www.cnblogs.com/liusuqi/p/3068652.html
Copyright © 2011-2022 走看看