asp c#写csv文件到客户端挂起下载



我正在尝试向客户端输出CSV文件。当保存对话框出现时(在Internet Explorer 10 & quot;Google Chrome),我试着从浏览器打开它,文件挂起并卡在"运行安全扫描"中。但是,我能够毫无问题地保存文件。下面是我用来生成文件的代码。还要注意的是,我已经尝试了HttpContext.Current.Response.End();HttpContext.Current.ApplicationInstance.CompleteRequest();,并得到了相同的结果。请帮助

        string attachment = "attachment; filename=" + "MyCSVFile.csv";
        var response = HttpContext.Current.Response;
        response.Clear();
        response.ClearHeaders();
        response.ClearContent();
        response.AddHeader("content-disposition", attachment);
        response.ContentType = "text/csv";
        var csv = new StringBuilder();
        // ... Build contents for csv file
        response.Write(csv.ToString());
        response.End(); 

显然,这个问题与我的代码无关,而是Windows中的一个损坏的文件。我通过使用Run as Administrator打开命令提示符并运行命令sfc/scannow来修复此问题。

最新更新