Search code examples
c#extractunzip

Cannot read that as a ZipFile for .exe file C#


I'm using SevenZIP library files to unzip/extract .exe file. When i tried this approcah I'm getting a error Cannot read that as a ZipFile & zip exception was unhanded. I don't want to use any 7zip.exe console app in my project & i prefer to use .dll files in my project.

Is there any other way to extract .exe file?

  private void MyExtract()
    {
        if(x86)
            ExtractZip(@"D:\22.1.2.702\64\953-win_x86.exe", ".");
        else
            ExtractZip(@"D:\22.1.2.702\64\.702-win_x64.exe", ".");
    }

    private void ExtractZip(string zipFile, string directory)
    {
        using (var zip1 = ZipFile.Read(zipFile))
        {
            // here, we extract every entry, but we could extract conditionally
            // based on entry name, size, date, checkbox status, etc.  
            foreach (var e in zip1)
            {
            e.Extract(directory, ExtractExistingFileAction.OverwriteSilently);
            }
        }
    }

Solution

  • Code sample looks like you are using DotNetZip and not SevenZipLib. DotNetZip can only extract .zip files, not 7-zip nor .exe.