Verify ZIP archive

May 25, 2009 at 1:11 PM


I wonder if there is a way to verify zip archive. I was thinking to try to list files and catch an exception but there should be a better way, right?

May 25, 2009 at 4:01 PM
Edited May 26, 2009 at 4:07 PM

I don't know of a better way.  ZipFile.IsZipFile() has a couple overloads that verify a zip file.  They do what you describe - list or extract all the entries in an archive, and catch any exceptions that occur.  If there are no exceptions, then the file is a valid bzip archive. 

The overload that extracts all the files will also check CRCs and so on.  It extracts them into a null stream, so nothing is written to disk or to memory - the data is just discarded. 

If you have a password-protected zip file, you currently need to do this validation yourself.