基本上用戶應該能夠點擊一個鏈接並下載多個PDF文件。但是Catch是我無法在服務器或任何地方創建文件的。一切都必須記憶。從內存流C創建Zip文件#
我能夠創建內存流和Response.Flush()它作爲pdf,但我怎麼壓縮多個內存流而不創建文件。
這裏是我的代碼:
Response.ContentType = "application/zip";
// If the browser is receiving a mangled zipfile, IIS Compression may cause this problem. Some members have found that
// Response.ContentType = "application/octet-stream" has solved this. May be specific to Internet Explorer.
Response.AppendHeader("content-disposition", "attachment; filename=\"Download.zip\"");
Response.CacheControl = "Private";
Response.Cache.SetExpires(DateTime.Now.AddMinutes(3)); // or put a timestamp in the filename in the content-disposition
byte[] abyBuffer = new byte[4096];
ZipOutputStream outStream = new ZipOutputStream(Response.OutputStream);
outStream.SetLevel(3);
#region Repeat for each Memory Stream
MemoryStream fStream = CreateClassroomRoster();// This returns a memory stream with pdf document
ZipEntry objZipEntry = new ZipEntry(ZipEntry.CleanName("ClassroomRoster.pdf"));
objZipEntry.DateTime = DateTime.Now;
objZipEntry.Size = fStream.Length;
outStream.PutNextEntry(objZipEntry);
int count = fStream.Read(abyBuffer, 0, abyBuffer.Length);
while (count > 0)
{
outStream.Write(abyBuffer, 0, count);
count = fStream.Read(abyBuffer, 0, abyBuffer.Length);
if (!Response.IsClientConnected)
{
break;
}
Response.Flush();
}
fStream.Close();
#endregion
outStream.Finish();
outStream.Close();
Response.Flush();
Response.End();
這將創建一個zip文件,但裏面有它沒有文件
我使用 使用iTextSharp.text - 使用ICSharpCode.SharpZipLib.Zip創建PDF - 爲荏苒
感謝, 卡維塔
您是否曾經找到過解決方案?我需要做同樣的事情。 – sbonkosky 2012-12-19 16:02:16
不,我沒有..我嘗試了所有的解決方案,但沒有任何工作..希望你找到它 – Arshya 2012-12-19 17:14:19
這個鏈接可能會有所幫助:http://snipplr.com/view/47762/ – updev 2013-11-19 21:49:31