是否有用于压缩大量文件的库或工具
我已经下载了 ICSharpCode.SharpZipLib 和 DotNetZip。我一次压缩 100 多个文件,大小从 1 兆到 4 兆不等。当我使用 ICSharpCode 时,出现“ContextSwitchDeadlock”错误。 DotNetZip 每次完成文件时都会失败。
另外,我正在处理共享点文件夹(映射到我的本地驱动器)
private bool zipall()
//ICSharpCode
{
int i = 0;
progressBarzipping.Minimum = 0;
progressBarzipping.Maximum = listBoxfiles.Items.Count;
ZipOutputStream zipOut = new ZipOutputStream(File.Create(textBoxDropPath.Text + "\\" + textBoxZipFileName.Text + ".zip"));
foreach (string fName in listBoxfiles.Items)
{
try
{
FileInfo fi = new FileInfo(fName);
ZipEntry entry = new ZipEntry(fi.Name);
FileStream sReader = File.OpenRead(fName);
byte[] buff = new byte[Convert.ToInt32(sReader.Length)];
sReader.Read(buff, 0, (int)sReader.Length);
entry.DateTime = fi.LastWriteTime;
entry.Size = sReader.Length;
sReader.Close();
zipOut.PutNextEntry(entry);
zipOut.Write(buff, 0, buff.Length);
}
catch
{
MessageBox.Show("Zip Failed");
zipOut.Finish();
zipOut.Close();
progressBarzipping.Value = 0;
return false;
}
i++;
progressBarzipping.Value = i;
}
zipOut.Finish();
zipOut.Close();
MessageBox.Show("Zip Complete");
progressBarzipping.Value = 0;
return true;
}
//Not sure but I think this was my DotNetZip approach
//using (ZipFile zip = new ZipFile())
// {
// foreach(string file in listboxFiles.Items)
// {
// zip.AddFile(file);
// }
// zip.Save(PathToNewZip);
// }
I've downloaded ICSharpCode.SharpZipLib and DotNetZip. I'm zipping over 100 files at a time varying a meg to 4 megs. When I use ICSharpCode I get a 'ContextSwitchDeadlock' error. DotNetZip fails on the finalizing of the file every time.
Also, I'm working on sharepoint folders (mapped to my local drive)
private bool zipall()
//ICSharpCode
{
int i = 0;
progressBarzipping.Minimum = 0;
progressBarzipping.Maximum = listBoxfiles.Items.Count;
ZipOutputStream zipOut = new ZipOutputStream(File.Create(textBoxDropPath.Text + "\\" + textBoxZipFileName.Text + ".zip"));
foreach (string fName in listBoxfiles.Items)
{
try
{
FileInfo fi = new FileInfo(fName);
ZipEntry entry = new ZipEntry(fi.Name);
FileStream sReader = File.OpenRead(fName);
byte[] buff = new byte[Convert.ToInt32(sReader.Length)];
sReader.Read(buff, 0, (int)sReader.Length);
entry.DateTime = fi.LastWriteTime;
entry.Size = sReader.Length;
sReader.Close();
zipOut.PutNextEntry(entry);
zipOut.Write(buff, 0, buff.Length);
}
catch
{
MessageBox.Show("Zip Failed");
zipOut.Finish();
zipOut.Close();
progressBarzipping.Value = 0;
return false;
}
i++;
progressBarzipping.Value = i;
}
zipOut.Finish();
zipOut.Close();
MessageBox.Show("Zip Complete");
progressBarzipping.Value = 0;
return true;
}
//Not sure but I think this was my DotNetZip approach
//using (ZipFile zip = new ZipFile())
// {
// foreach(string file in listboxFiles.Items)
// {
// zip.AddFile(file);
// }
// zip.Save(PathToNewZip);
// }
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你没有提供例外。使用 DotNetZip 时,我猜想问题可能出在共享点映射驱动器上。 DotNetZip 通常会将 zip 保存为临时文件,然后重命名。也许由于共享点,这不起作用。如果是这种情况,请尝试打开文件流并将其保存到该流。这避免了重命名操作。
You didn't provide the exception. When using DotNetZip, I guess the problem might be with the sharepoint mapped drive. DotNetZip normally will save the zip as a temp file, then rename it. Maybe this isn't working because of sharepoint. If that's the case, try opening a filestream and saving it to that stream. This avoids the rename operation.