我正在尝试从 winform 应用程序中解压缩文件。 我正在使用这段代码:
string dezarhiverPath = @AppDomain.CurrentDomain.BaseDirectory + "\\7z.exe";
ProcessStartInfo pro = new ProcessStartInfo();
pro.WindowStyle = ProcessWindowStyle.Hidden;
pro.FileName = dezarhiverPath;
pro.Arguments = @" e c:\TEST.ZIP";
Process x = Process.Start(pro);
x.WaitForExit();
代码不返回错误但不返回任何内容。 我也从 cmd 尝试过这个命令:
K:\>"C:\Test\7z.exe" e "c:\TEST.ZIP"
但在 cmd 中,我收到此错误消息:
7-Zip cannot find the code that works with archives.
谁能帮我从 C# 中解压一些文件?
谢谢!
最佳答案
您为什么要尝试在外部使用 7z.exe 应用程序?这是一种非常笨拙的做法。而是使用您可以随意使用的众多库之一。
如果这是一个新的应用程序,并且您的目标是 .NET 4.5,新的 System.IO.Compression
命名空间有一个 ZipFile
类。
或者,SharpZipLib
是用于 .NET 中文件压缩的 GPL 库。有online samples .
也可用 DotNetZip这是 Ms-PL 许可的。
关于c# - 使用 7z.exe 在 C# 中解压缩文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16558363/