如何使用 Squid-Box.SevenZipSharp 在 C# 上压缩和解压缩文件 执行失败错误
Posted
技术标签:
【中文标题】如何使用 Squid-Box.SevenZipSharp 在 C# 上压缩和解压缩文件 执行失败错误【英文标题】:How to Zip and UnZip Files on C# using Squid-Box.SevenZipSharp Execution has failed error 【发布时间】:2021-07-18 17:59:31 【问题描述】:我最近尝试使用 NuGet "Squid-Box.SevenZipSharp" 压缩和解压缩文件 但是我无法压缩它们,错误可能来自 dll 库。我试过下载 32 位和 64 位的 7zip,同时使用 .dll 但错误是一样的,我想不出有什么办法。
private void Compress(string source, string output)
/*32-bits version*/ string path = Directory.GetCurrentDirectory() + @"\32-7z.dll";
//64-bits version string path = Directory.GetCurrentDirectory() + @"\64-7z.dll";
SevenZipCompressor compressor = new SevenZipCompressor();
compressor.ArchiveFormat = OutArchiveFormat.Zip;
compressor.TempFolderPath = Path.GetTempPath();
compressor.CompressionMode = SevenZip.CompressionMode.Create;
compressor.CompressionLevel = SevenZip.CompressionLevel.Fast;
compressor.CompressionMethod = CompressionMethod.Lzma2;
compressor.ZipEncryptionMethod = ZipEncryptionMethod.Aes256;
var assemblyDllPath = compressor.TempFolderPath + "32-7z.dll";
//var assemblyDllPath = compressor.TempFolderPath + "64-7z.dll";
File.Copy(path, assemblyDllPath, overwrite: true);
SevenZipExtractor.SetLibraryPath(path);
compressor.CompressDirectory(@"A:\C#\random", @"A:\C#\empty\archive.zip", "password");
当我使用 32 位 dll 时,proyect 设置为 Debug x86。 当我使用 64 位 dll 时,proyect 设置为 Debug x64。
两种情况的错误如下:
SevenZip.SevenZipException
HResult=0x80131500
Message = Execution has failed due to an internal SevenZipSharp issue (0x80004001 / -2147467263).
Please report it to https://github.com/squid-box/SevenZipSharp/issues/, include the release number, 7z version used, and attach the archive.
Source = SevenZipSharp
非常感谢您为此付出的时间,在此先感谢。
【问题讨论】:
听起来由于内部 SevenZipSharp 问题而失败。或许您应该将其报告给github.com/squid-box/SevenZipSharp/issues,并附上发布号、使用的 7z 版本,并附上存档。 看来要等很久才能得到答复,反正我开了票,你总要抱希望 This question on stack overflow 可以帮助你,它是如何下载和解压缩文件,我也确信你不需要任何 dll 或包,因为 windows 可以处理 .zip 文件 【参考方案1】:您收到的错误代码 (0x80004001) 对应于“未实现”错误 - 这是因为您尝试使用 .zip 格式不支持的 CompressionMethod。
除非您有特殊要求,否则我建议您使用 CompressionMode.Default
- 否则以下 .zip 格式适用:
CompressionMethod.Copy
CompressionMethod.Deflate
CompressionMethod.Deflate64
CompressionMethod.BZip2
CompressionMethod.Lzma
CompressionMethod.Ppmd
这是我从github上的squid-box得到的答案,把CompressionMethod.Lzma2
改成CompressionMethod.Lzma
【讨论】:
以上是关于如何使用 Squid-Box.SevenZipSharp 在 C# 上压缩和解压缩文件 执行失败错误的主要内容,如果未能解决你的问题,请参考以下文章
如何在自动布局中使用约束标识符以及如何使用标识符更改约束? [迅速]
如何使用 AngularJS 的 ng-model 创建一个数组以及如何使用 jquery 提交?