Я пытаюсь создать ZIP-файл на лету, который может содержать несколько тысяч изображений.
public static void CompressAndSendFiles (Список файлов)
{
HttpContext.Current.Response.ClearContent ();
// LINE1: Add the file name and attachment, which will force the open/cance/save dialog to show, to the header
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=\"Jpeg Package "
+ DateTime.Now.ToString("MM-dd-yyyy hh-mm-ss") + ".zip\"");
// Add the file size into the response header
//HttpContext.Current.Response.AddHeader("Content-Length", file.Length.ToString());
// Set the ContentType
HttpContext.Current.Response.ContentType = ReturnHttpContentType("download.zip");
ZipOutputStream oZipStream =
new ZipOutputStream(HttpContext.Current.Response.OutputStream);
try
{
foreach (string file in files)
{
FileInfo fInfo = new FileInfo(file);
ZipEntry oZipEntry = new ZipEntry(fInfo.Name);
oZipStream.PutNextEntry(oZipEntry);
byte[] buffer = File.ReadAllBytes(file);
oZipStream.Write(buffer, 0, buffer.Length);
//oZipStream.Flush();
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
oZipStream.Finish();
oZipStream.Close();
oZipStream.Dispose();
}
HttpContext.Current.Response.OutputStream.Flush();
HttpContext.Current.Response.End();
}
Все хорошо, если только количество файлов не стало большим.
Мой вопрос:
Есть ли способ инициировать загрузку (разрешить всплывающее окно диспетчера загрузки на стороне клиента), а затем начать запись в потоке?
Я наблюдал за процессом w3wp.exe (IIS), и похоже, что данные записываются в память вместо Stream. Когда использование памяти w3wp.exe обогащает определенное число, оно освобождает память и ничего не происходит (загрузка не производится).
Заранее спасибо.