extract 7zip in C# code

前端 未结 4 1079
遥遥无期
遥遥无期 2020-12-01 22:44

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

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

but I don\'t know h

相关标签:
4条回答
  • 2020-12-01 23:09

    The authors of 7zip provide the LZMA SDK and good documentation which should be able to achieve what you want. The SDK includes C# code capable of compression / decompression.

    Another option would be to use a something like C# (.NET) Interface for 7-Zip Archive DLLs

    UPDATE: Another user asked a similar question here: How do I create 7-Zip archives with .NET? The answer has several of the same links I provided and a few more.

    0 讨论(0)
  • 2020-12-01 23:12

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

    You need those 3 Files added in the project:

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

    Don't forget to say Copy to Output Directory in it's preferences.

    Extract an 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 an 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();
    }
    
    0 讨论(0)
  • 2020-12-01 23:18

    The 7zSharp library doesn't seem to support password as input, just a zip file.

    The library just calls the .exe of 7zip, so you could donwload the source and alter it to accept a password parameter which you then pass to the executable.

    0 讨论(0)
  • 2020-12-01 23:23

    It doesn't look like this library supports encrypted files. No method takes a key as a parameter.

    0 讨论(0)
提交回复
热议问题