使用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:\Test\7z.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
命名空间有一个<一个HREF =http://msdn.microsoft.com/en-us/library/system.io.compression.zipfile.aspx> 的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屋!