简体   繁体   中英

Download multiple zip files asp.net


I want to download multiple zipped files at once - and not putting them into 1 zipfile. I want them separately.


I have this code snippet below where the input is from a loop of reportnames that the user have chosen.

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);
            }
        }
    }

This works fine, but just with 1 file.
This makes sense due to the 1 to 1 relationship between One request = One response.

But are there any way I can do this smother than zipping them all into 1 file?

Thankful for all help.

Each request can only have one response. This means you are trying to work against the protocol.

But you could achieve this by multiple requests from the browser. The solution lies in the client code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM