User (Old forums)MemberSeptember 24, 2008 at 4:27 pmPost count: 23064
I hate to post this because I feel it must have been asked many times before. I have searched the forum, reviewed the documentation but I just don’t see it.
How do you test the validity of a zip archive?
I use another 3rd party library that simply has a testArchive() method that returns a boolean value. True if the zip is good and false if it is corrupt in any way. Since I am already using Xceed FTP to retrieve the zip file from a remote site, I would like to use either C# or Xceed to test the zip.
Imported from legacy forums. Posted by Chris (had 1722 views)User (Old forums)MemberSeptember 26, 2008 at 9:38 amPost count: 23064
The component does not offer this feature. However, it can be easily implemented by simply getting an instance of each file in the zip archive, open a stream on each, and read it through. This will first make sure that the archive itself is valid (central directory), and each file is valid (the CRC will be checked) and can be unzipped.
private void ValidateArchive( string archiveToTest )
DiskFile zip = new DiskFile( archiveToTest );
if( zip.Exists )
ZipArchive archive = new ZipArchive( zip );
byte buffer = new byte[ 32768 ];
int bytesRead = 0;
foreach( ZippedFile zippedFile in archive.GetFiles( true ) )
using( Stream sourceFile = zippedFile.OpenRead() )
while( ( bytesRead = sourceFile.Read( buffer, 0, buffer.Length ) ) > 0 )
catch( Exception ex )
//place a true exception handling routine here; if an exception is thrown,
//this means there is a problem with the archive
Debug.WriteLine( ex.ToString() );
Imported from legacy forums. Posted by André (had 525 views)User (Old forums)MemberOctober 1, 2008 at 3:43 pmPost count: 23064
Someone asked me for the VB.NET version, so here it is :
Private Sub ValidateArchive( ByVal archiveToTest As String )
Dim zip As New DiskFile( archiveToTest )
If zip.Exists Then
Dim archive As New ZipArchive( zip )
Dim buffer( 32767 ) As Byte
Dim bytesRead As Integer = 0
For Each zippedFile As ZippedFile In archive.GetFiles( True )
Using sourceFile As Stream = zippedFile.OpenRead()
bytesRead = sourceFile.Read( buffer, 0, buffer.Length )
Loop While bytesRead > 0
Catch ex As Exception
‘place a true exception handling routine here; if an exception is thrown,
‘this means there is a problem with the archive
Debug.WriteLine( ex.ToString() )
Imported from legacy forums. Posted by André (had 1320 views)
- You must be logged in to reply to this topic.