下载管理器启动后,HttpContext.Current.Response写入文件
我正在尝试创建一个可能包含数千张图片的ZIP文件。
public static void CompressAndSendFiles(List files)
{
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内存使用量增加一定数量时,它释放内存并且没有任何反应(没有下载)。
先感谢您。
没有找到相关结果
已邀请:
2 个回复
搜洼挂时
惜堡沁戚