Home › Forums › .NET libraries › Xceed Zip & Real-Time Zip for .NET › test if zip file is password protected
-
AuthorPosts
-
#20295 |
I need to check if a zip file is password protected before attempting to reveal the contents. Is there a function that allows me to do that?
Imported from legacy forums. Posted by Dan (had 1172 views)
Hi Dan,
You could verify that the ZippedFile was password protected by checking the value of the ZippedFile’s Encrypted property. The documentation on this property is available at: http://doc.xceedsoft.com/products/xceedfilesystem/Xceed.Zip~Xceed.Zip.ZippedFile~Encrypted.html.
Imported from legacy forums. Posted by Mohamed [Xceed] (had 190 views)
That works! Thanks.
As a future enhancement it would be nice to be able to do a password test.
Imported from legacy forums. Posted by Dan (had 1218 views)
This is not working for me I need to check, is this zip file is password protected or not? any idea how I can check that with xceed?
Hi,
The Zip file format allows every item that is part of the archive to be individually encrypted or not.
As such, in the Xceed Zip for .NET component, the ZippedFile object contains a Encrypted property that specifies if the zipped item the object represents is encrypted or not. This is the only property which can be checked in this regard.
Documentation:
http://forums.xceed.com/wp-content/documentation/xceed-filesystem-for-net/webframe.html#topic7888.htmlTo use the property, if you know the name of a specific file in the archive you are using:
AbstractFile zipFile = new DiskFile( @”Case165655.zip” );
ZipArchive zip = new ZipArchive( zipFile );// Get your file that is in the archive
ZippedFile zippedFile = ( ZippedFile ) zip.GetFile( “MyFile.dat” );// Get whether it is encrypted or not
bool encrypted = zippedFile.Encrypted;If, however, you do not know the name of a file in the archive:
// Get the files in the archive
AbstractFile[] files = zip.GetFiles( true );// If we have at least one file
if( files.Length > 0 )
{
// Take the first file and cast it as a ZippedFile
ZippedFile zippedFile = ( ZippedFile ) files[ 0 ];// Get whether it is encrypted or not
bool encrypted = zippedFile.Encrypted;
}To actually decrypt the items in your archive:
zip.DefaultDecryptionPassword = “my password”;
AbstractFolder destinationFolder = new DiskFolder( @”MyFolder” );
zip.CopyFilesTo( destinationFolder, true, true ); -
AuthorPosts
- You must be logged in to reply to this topic.