나는 수천 장의 그림이 포함 된 ZIP 파일을 즉석에서 만들려고합니다.HttpContext.Current.Response 다운로드 관리자가 시작한 후 파일 쓰기
공공 정적 무효 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) 프로세스를 모니터링했는데 데이터가 스트림 대신 메모리에 기록되는 것으로 보입니다. w3wp.exe 메모리 사용량이 일정한 수치를 초과하면 메모리를 해제하고 아무 것도 발생하지 않습니다 (다운로드하지 않음).
미리 감사드립니다.
해피 250k 담당자! (글쎄, 아직은 아니지만, 때 안타 :)) – RCIX
고마워요! C# 신의 이중성은 없습니다! –
안녕 Arash, 나도 같은 문제가있어. 이 문제를 어떻게 해결했는지 최종 코드를 보여 주시겠습니까? –