Fiona
Fiona

Reputation: 1599

System.IO.Compression End of Central Directory record could not be found

On executing the following code.. I get an exception on the OpenRead statement:

End of Central Directory record could not be found.

I am however able to open the zip file with no issues through windows explorer.

Any thoughts?

string zipPath = @"c:\testfiles\MMM_C13000_2016M08.zip";
   using (ZipArchive archive = ZipFile.OpenRead(zipPath))
   {
       foreach (ZipArchiveEntry entry in archive.Entries)
       {
       }
   }

Upvotes: 6

Views: 12049

Answers (1)

Mark Adler
Mark Adler

Reputation: 112404

It is possible to process a zip file in two different ways. You can simply read sequentially from the beginning, processing local headers and compressed data as you go. Or you can use the central directory at the end of the zip file to find the entries and process them by seeking in the file.

It appears that the zip file is damaged or has junk at the end that is preventing one method from working, but not the other.

Upvotes: 2

Related Questions