I have created a very simple program in C# using the DotNetZip dll. I am trying to extract a zip file that chooses the best compression. Here is the code.

static void Main(string[] args)
    {
        string nameOfFile = "testBest.zip";
        string directory = "testBest";

        Console.WriteLine("Extracting file {0} to {1}", nameOfFile, directory); 

        using (ZipFile zip = ZipFile.Read(nameOfFile))
        {
            foreach (ZipEntry e in zip)
            {
                e.Extract(directory, ExtractExistingFileAction.OverwriteSilently);
            }
        }
    }

And the error says one of the txt files uses an unsupported compression method.

Can the DotNetZip library not extract zip files when using Best compression? Is there a way to handle this? What are the alternatives?

有帮助吗?

解决方案

I would imagine that the zip compression being used is not one of the supported ones. Here is an example forum post where this was the case: http://dotnetzip.codeplex.com/discussions/64680

In this case, the compression of DEFLATE64 was used instead of DEFLATE, giving the same error you are seeing. While your entire error text would be more helpful, it will probably come down to the same thing - the library does not support your compression method.

其他提示

hey here i created the extract method. you need to give full path of directory like c:\temp\temp.zip

  public void MyExtractZip(string FileName,string Password)
        {
            string ExtractLocation = string.Empty;
            using (ZipFile zip = ZipFile.Read(FileName))
            {
                // here, we extract every entry, but we could extract conditionally
                // based on entry name, size, date, checkbox status, etc. 
                string ArchiveName =Path.GetFileNameWithoutExtension(FileName);
                Console.WriteLine("[1] Extract Here [2] Extract too [3] Extract to "+ArchiveName);
                Console.WriteLine("\n");
                Console.Write("Select your option :: \t");
                 string entry = Console.ReadLine();
                 int n = int.Parse(entry);

                string Location =string.Empty;
                if (n == 2)
                {
                    Console.Write("Enter the Location ::" );
                    Location = Console.ReadLine();

                }
                Console.Write("\n");
                switch (n)
                {
                    case 1:
                        ExtractLocation=Path.GetDirectoryName(FileName);
                        break;
                    case 2:
                        ExtractLocation = Location + "\\"; 
                        break;
                    case 3:
                        ExtractLocation = Path.GetDirectoryName(FileName) + "\\"+Path.GetFileNameWithoutExtension(FileName);
                        break;
                }
                zip.Password = Password;
                foreach (ZipEntry e in zip)
                {
                    e.Extract(ExtractLocation, ExtractExistingFileAction.OverwriteSilently);
                }

            }
        }
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top