how to get around corrupted zip files

May 23, 2011 at 8:59 PM

when I have a corrupted zip file, my program throws an exception and leaves the "for loop" (actually, all the for loops). what should I do to skip the corrupted zip file (maybe throwing a message box) and continue extracting files from the next zip file. the code where the exception is thrown because of the corrupted zip file, is :

ZipFile ^zip =


gcnew ZipFile(ZippedNames[i]);


P.S. Also, the way I know the zip file is corrupted, when I double click on the zip file itself from windows explore, I get the following message:

"cannot open file: it does not appear to be valid archive, if you downloaded this file, try downloading the file again"

P.S. Also, I don't want to use Try-Catch allover my code if there is a better way. Thanks.

May 26, 2011 at 12:04 PM

Try..catch is the way to handle exceptions in .NET.