[英]Download multiple zip files asp.net
我想一次下載多個壓縮文件-而不是將它們放入1個zipfile中。 我要他們分開。
我在下面有此代碼段,其中輸入來自用戶選擇的報告名稱循環。
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個文件之外,還有什么方法可以使我更順利嗎?
感謝所有的幫助。
每個請求只能有一個響應。 這意味着您正在嘗試違反該協議。
但是您可以通過瀏覽器的多個請求來實現。 解決方案在於客戶端代碼。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.