错误,当创建一个使用DotNetZip Zip文件:压缩文件意外结束 [英] Error when creating Zip file using DotNetZip: Unexpected end of archive
问题描述
我有拉链向上使用DotNetZip一个或多个文件的方法,并且已经正常工作。我今天收到错误的第一时间,它似乎与存档的总大小。使用相同的60MB .TIFF图像,我会添加一些额外的副本,测试,重复。它工作得很好,直到加入约10张图像,然后,当我打开用winrar Zip文件,我会得到错误档案意外结束。以这种方式测试,我相信我已经排除了被涉及到我的code或文件(被损坏或东西)的问题。在code没有错误,只有WinRAR的。当我打开Zip文件,有一个大小为0的只显示一个文件所以好像被达到某种大小限制,它不是允许创建存档。我只是不知道这限制了它。这里是我的code,如果它可以帮助:
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ContentType =应用程序/压缩
HttpContext.Current.Response.AddHeader(内容处置,文件名=+MyFileName的+ DateTime.Now.ToString(MMDDYYYY)+.ZIP);使用(VAR邮编=新Ionic.Zip.ZipFile())
{
zip.MaxOutputSegmentSize = 819200; //我尝试添加这并没有解决问题 的foreach(在文件var文件)
{
zip.AddFile(file.FileLocation,file.ZipFileDirectory).FileName =
(!string.IsNullOrEmpty(file.ZipFileDirectory)及及(file.ZipFileDirectory = @\\)!)?
的String.Format(@{0} \\ {1},file.ZipFileDirectory,file.FileName):
file.FileName;
} zip.Save(HttpContext.Current.Response.OutputStream);
}
你需要你写完它后刷新流?
HttpContext.Current.Response.Flush();
编辑:
呼叫HttpContext.Current.ApplicationInstance.CompleteRequest()
I have a method that zips up one or more files using DotNetZip, and it has been working correctly. I received an error for the first time today and it appears to be related to the total size of the archive. Using the same 60mb .tiff image, I would add a few extra copies, test, repeat. It worked fine until about 10 images were added, then, when I opened the Zip file using WinRar, I would get the "Unexpected end of archive" error. Testing in this manner, I believe I've ruled out the problem being related to my code or the files (being corrupt or something). The code does not error, only WinRar. When I open the Zip file, there is only one file displayed with a size of "0." So it seems like some sort of size limit is being reached and it's not allowing the archive to be created. I just don't know which limit it is. Here is my code, if it helps:
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ContentType = "application/zip";
HttpContext.Current.Response.AddHeader("content-disposition", "filename=" + "MyFileName" + DateTime.Now.ToString("MMddyyyy") + ".zip");
using (var zip = new Ionic.Zip.ZipFile())
{
zip.MaxOutputSegmentSize = 819200; // I tried adding this and it did not fix the problem
foreach (var file in files)
{
zip.AddFile(file.FileLocation, file.ZipFileDirectory).FileName =
(!string.IsNullOrEmpty(file.ZipFileDirectory) && (file.ZipFileDirectory != @"\")) ?
string.Format(@"{0}\{1}", file.ZipFileDirectory, file.FileName) :
file.FileName;
}
zip.Save(HttpContext.Current.Response.OutputStream);
}
Do you need to Flush the stream after your are done writing to it?
HttpContext.Current.Response.Flush();
EDIT:
Call HttpContext.Current.ApplicationInstance.CompleteRequest()
这篇关于错误,当创建一个使用DotNetZip Zip文件:压缩文件意外结束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!