【问题标题】:Download multiple zip files asp.net下载多个 zip 文件 asp.net
【发布时间】:2019-07-18 22:27:32
【问题描述】:


我想一次下载多个压缩文件 - 而不是将它们放入 1 个压缩文件中。我想要它们分开。


我在下面有这段代码 sn-p,其中输入来自用户选择的报告名称循环。

public static void ExecuteDownloadInBrowser(string reportPrefix)
    {
        string zippedFilePath = baseZippedFolderPath + reportPrefix + ".zip";
        FileInfo file = new FileInfo(zippedFilePath);
        if (file.Exists)
        {
            try
            {
                HttpContext.Current.Response.Clear();
                HttpContext.Current.Response.ClearHeaders();
                HttpContext.Current.Response.ClearContent();
                HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);
                HttpContext.Current.Response.AddHeader("Content-Length", file.Length.ToString());
                HttpContext.Current.Response.ContentType = "text/plain";
                HttpContext.Current.Response.Flush();
                HttpContext.Current.Response.TransmitFile(file.FullName);
                HttpContext.Current.Response.End();

                WriteToLog("Downloadling file: " + file.Name + " in browser succeded");
            }
            catch(Exception ex)
            {
                WriteToLog("Error downloading file in browser. Message: " + ex.Message);
            }
        }
    }

这很好用,但只有 1 个文件。
这是有道理的,因为一个请求 = 一个响应之间存在 1 对 1 的关系。

但是除了将它们全部压缩到一个文件中之外,我还有什么办法可以做到这一点?

感谢大家的帮助。

【问题讨论】:

    标签: c# asp.net httpcontext


    【解决方案1】:

    每个请求只能有一个响应。这意味着您正在尝试违反协议。

    但是您可以通过来自浏览器的多个请求来实现这一点。解决方案在于客户端代码。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-02-21
      • 2019-03-01
      • 2018-02-09
      • 1970-01-01
      • 1970-01-01
      • 2012-12-20
      • 1970-01-01
      • 2010-12-17
      相关资源
      最近更新 更多