基本上用户应该能够点击一个链接并下载多个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