• 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();
    }
  • 相关阅读:
    String、StringBuffer、StringBuilder源码解读
    查询条件左边写入函数,导致无法命中索引
    【图形学手记】law of the unconscious statistician
    【图形学手记】蒙特卡洛方法相关笔记
    【图形学手记】抽样分布相关的数学笔记
    C++ lower_bound
    【图形学手记】Inverse Transform Sampling 逆转换抽样
    【Java学习笔记】LinkedList JDK1.6
    【疑难杂症】new Date() 造成的线程阻塞问题
    【疑难杂症】【Solved】maven-compiler-plugin 在 idea 下的问题
  • 原文地址:https://www.cnblogs.com/Amity/p/2977763.html
Copyright © 2020-2023  润新知