How to Validate a zip file using DotNetZip Library?

Nov 25, 2009 at 10:18 AM
Edited Nov 25, 2009 at 10:20 AM

I need to validate that a zip archive is not corrupted.

Obviously one way to do that is to open the ZipFile and then extract each file to a temp directory and then delete the extracted files. If all goes well it's valid.

However, that's a little bit messy. Is there a neater way of doing this (like extracting to a memory stream or simply iterating through the zipEntries (perhaps it validates them at that point))?


Thanks in advance,


Nov 25, 2009 at 10:44 AM

Never mind. As always I found the answer straight after I posted.

There are two overloaded methods to do this:

bool ZipFile.CheckZip(string zipFileName);

bool ZipFile.CheckZip(string zipFileName, bool fixIfNecessary, out System.Collections.ObjectModel.ReadOnlyCollection<string> messages);


Sep 27, 2010 at 10:10 PM

is there a way to check a specific file inside a .Zip?

the Above will tell me the Zip file is good, but Maybe the file that I just tried to append to it didn't work correctly.  (trying to do what the -m option does on Winzip Command Line)

I want to delete the input file after Zipping, but I need to verify that the File was succesfully put into the zip file.

I would rather not do a complete Unzip because I will have a zip file with MANY Large files in it.




Sep 29, 2010 at 5:40 AM
The way to check an entry in a zipfile is to extract the entry. This verifies that the compression is valid, checks any passwords, and verifies the file crc. To do the check as quickly as possible, extract to Stream.Null, which will eliminate all unnecesary IO.