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

1

6

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)
       {
       }
   }
Calorific answered 8/9, 2016 at 12:11 Comment(0)
J
2

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.

Jamey answered 8/9, 2016 at 13:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.