zoukankan      html  css  js  c++  java
  • Ajax得到服务器生成的文件流,下载

    前台:

           var downloadFrame;
            function doHisRPTDownload() {
                var period = $("#" + "<%=MonthSelect.ClientID %>").val();
                // Check to be sure this async postback is actually requesting the file download.    
                if (!downloadFrame) {
                    downloadFrame = document.createElement("iframe");
                    // Add the IFRAME to the page.  This will trigger a request to GenerateFile now.       
                    document.body.appendChild(downloadFrame);
                    // This makes the IFRAME invisible to the user.       
                    downloadFrame.style.display = "none";
                }
                // Point the IFRAME to GenerateFile, with the desired region as a querystring argument.   
                downloadFrame.src = "AjaxPage/WebAjaxExportHisRPT.aspx?period=" + period;
                setTimeout("downloadFrame.src=''", 6000);
            }
     
    后台:
    public void GenerateXLS(DataTable dtstring fileNamestring sheetNameint[] colWidthint[]colWidthCriteriastring selectionCriteria)
            {
                byte[] fileData = nrpt.GetMemoryStream(dtsheetNamecolWidthcolWidthCriteria,selectionCriteria).ToArray();
                this.Response.Clear();
                this.Response.ContentEncoding = System.Text.Encoding.Default;
                this.Response.ContentType = "application/vnd.ms-excel"// "application/octet-stream"; //"application/ms-excel"; //vnd.
                this.Response.AppendHeader("content-disposition""attachment; filename=" +HttpUtility.UrlEncode(fileNameSystem.Text.Encoding.UTF8).Replace("+""%20"));
                this.Response.OutputStream.Write(fileData0fileData == null ? 0 : fileData.Length);
                this.Response.Flush();
                this.Response.End();
    }
  • 相关阅读:
    Clojure实现的简单短网址服务(Compojure、Ring、Korma库演示样例)
    android4.4系统解决“ERRORcouldn&#39;t find native method”方法
    JS window.open()属性
    网页视频播放器代码大全 + 21个为您的站点和博客提供的免费视频播放器
    理解Java的GC日志
    图像识别技术
    堆排序原理及算法实现(最大堆)
    什么是依赖注入
    Cocos2d-x3.1下实现相似iOS页面滑动指示圆点
    [Bootstrap] 6. Navigation
  • 原文地址:https://www.cnblogs.com/Amity/p/2977763.html
Copyright © 2011-2022 走看看