用C#代码提取7zip

kod*_*der 5 .net c# 7zip

我需要在C#中使用7zip.没有控制台,只有7zSharp.dll?+我在这里找到一些数据

http://7zsharp.codeplex.com/releases/view/10305,

但我不知道如何使用它( - 我可以创建.bat(.cmd)文件,但我需要通过dll文件)正好:我需要提取.7z文件与键)

Vis*_*Sen 14

从7zip.com下载独立控制台版本并将其添加到您的项目中.

您需要在项目中添加这3个文件:

  1. 7za.exe
  2. 了7za.dll
  3. 7zxa.dll

不要忘记在其偏好中说复制到输出目录.

提取存档:

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
        }
    }
Run Code Online (Sandbox Code Playgroud)

创建档案:

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();
}
Run Code Online (Sandbox Code Playgroud)


rob*_*hoo 7

7zip 的作者提供了LZMA SDK和良好的文档,应该能够实现您想要的。该 SDK 包含能够压缩/解压缩的 C# 代码。

另一种选择是使用C# (.NET) Interface for 7-Zip Archive DLL

更新: 另一位用户在这里提出了类似的问题:How do I create 7-Zip archives with .NET? 答案有几个与我提供的相同的链接以及更多链接。


Chr*_*ård 0

这个库看起来不支持加密文件。没有方法将键作为参数。