使用Context.ApplicationInstance.CompleteRequest()替换Response.Close后,HTML标记文本将附加到csv downloadfile

时间:2014-06-17 10:36:36

标签: c# .net asp-classic

        HttpContext.Current.Response.Buffer = false;
        HttpContext.Current.Response.Charset = string.Empty;
        HttpContext.Current.Response.ClearContent();
        HttpContext.Current.Response.ClearHeaders();
        HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=Ro.csv");                                        
        HttpContext.Current.Response.AddHeader("Pragma", "public");
        HttpContext.Current.Response.ContentType = "application/force-download\n";

        this.EnableViewState = false;
        int i = 0;
        while (i < RO.Count)
        {
            roDataRow = (Business.RO)ROi];

            if (i == 0)
            {
                HttpContext.Current.Response.Write(roDataRow.GetCSVFieldNames(isSalesReport));
            }

            HttpContext.Current.Response.Write(roDataRow.ToCSVString(isSalesReport));

            i++;
        }
        HttpContext.Current.Response.Flush();
        this.Context.ApplicationInstance.CompleteRequest();

        Session["ReportData"] = null;

由于IN IE10 CSV下载失败,我更换了HttpContext.Current.Response.Close(); with this.Context.ApplicationInstance.CompleteRequest();下载问题已解决,但下载的文件附加了html内容。如何使html内容不附加到下载文件

0 个答案:

没有答案