在 C# 代码中提取 7zip [英] extract 7zip in C# code
本文介绍了在 C# 代码中提取 7zip的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要在 C# 中使用 7zip.没有控制台,只有 7zSharp.dll ?+ 我在这里找到了一些数据
I need use 7zip in C#. Without console, just with 7zSharp.dll ? + I find some data here
http://7zsharp.codeplex.com/releases/view/10305 ,
但我不知道如何使用它( - 我可以创建 .bat(.cmd) 文件,但我需要通过 dll 文件)正是:我需要使用密钥提取 .7z 文件)
but I don't know how to use it( - I could create .bat(.cmd) file, but I need throught dll file) Exactly: I need extract .7z file with key)
推荐答案
从以下位置下载独立控制台版本7zip.com 并将其添加到您的项目中.
Download the standalone console version from 7zip.com and add it to your project.
您需要在项目中添加这 3 个文件:
You need those 3 Files added in the project:
- 7za.exe
- 7za.dll
- 7zxa.dll
不要忘记在它的首选项中说复制到输出目录.
Don't forget to say Copy to Output Directory in it's preferences.
提取档案:
public void ExtractFile(string sourceArchive, string destination)
{
string zPath = "7za.exe"; //add to proj and set CopyToOuputDir
try
{
ProcessStartInfo pro = new ProcessStartInfo();
pro.WindowStyle = ProcessWindowStyle.Hidden;
pro.FileName = zPath;
pro.Arguments = string.Format("x "{0}" -y -o"{1}"", sourceArchive, destination);
Process x = Process.Start(pro);
x.WaitForExit();
}
catch (System.Exception Ex) {
//handle error
}
}
创建存档:
public void CreateZip(string sourceName, string targetArchive)
{
ProcessStartInfo p = new ProcessStartInfo();
p.FileName = "7za.exe";
p.Arguments = string.Format("a -tgzip "{0}" "{1}" -mx=9", targetArchive, sourceName);
p.WindowStyle = ProcessWindowStyle.Hidden;
Process x = Process.Start(p);
x.WaitForExit();
}
这篇关于在 C# 代码中提取 7zip的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文