Extract 7zip in C # code

I need to use 7zip in C #. Without a console, only with 7zSharp.dll? + I find here some data

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

but I don't know how to use it (- I could create a .bat file (.cmd), but I need a dll dll file) Exactly: I need to extract the .7z file with the key)

+5
source share
4 answers

Download the standalone version of the console from 7zip.com and add it to your project.

You need these 3 files added to the project:

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

Do not forget to say "Copy to output directory" in the settings.

Extract archive:

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
        }
    }

Create archive:

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();
}
+7

7zip LZMA SDK , , . SDK #, /.

- # (.NET) DLL 7-

UPDATE: : 7-Zip- .NET? , , .

+3

, . .

0

The 7zSharp library does not seem to support the password as an input, but just a zip file.

The library simply calls the .exe file from 7zip, so you can download the source and change it to accept the password parameter, which is then passed to the executable.

0
source

All Articles