使用 7z.exe 在 c# 中解压缩文件 [英] Unzip a file in c# using 7z.exe
问题描述
我正在尝试从 winform 应用程序解压缩文件.我正在使用此代码:
I'm trying to unzip a file from a winform application. I'm using this code :
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 尝试了这个命令:
The code doesn't return error but doesn't anything. I tried this command also from cmd :
K:>"C:Test7z.exe" e "c:TEST.ZIP"
但在 cmd 中,我收到此错误消息:
but in cmd ,I receive this error message :
7-Zip cannot find the code that works with archives.
有人可以帮我从 C# 中解压一些文件吗?
Can somebody help me to unzip some files from c# ?
谢谢!
推荐答案
您为什么要费心尝试在外部使用 7z.exe 应用程序?这是一种非常笨拙的方法.而是使用您可以使用的众多库之一.
Why would you bother trying to use the 7z.exe application externally? That is a very kludgy way of doing it. Instead use one of the many libraries at your disposal.
如果这是一个新应用程序,并且您的目标是 .NET 4.5,则新的 System.IO.Compression
命名空间有一个 ZipFile
类.
If this is a new application, and you are targeting .NET 4.5, The new System.IO.Compression
namespace has a ZipFile
class.
或者,SharpZipLib
是用于文件压缩的 GPL 库在 .NET 中.有在线示例.
还有 DotNetZip 已获得 Ms-PL 许可.
Also available is DotNetZip which is Ms-PL licensed.
这篇关于使用 7z.exe 在 c# 中解压缩文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!