User (Old forums)MemberFebruary 12, 2007 at 8:14 amPost count: 23064
Hi, I read on the product page that Zip for .NET allows to overwrite read-only files. Unfortunately, I always get an exception when I try to unzip a ZIP archive and some of the files already exist in the target location (and have the read-only flag set).
How can I get “Zip for .NET” to overwrite the read-only files?
I’m using version 2.3.5479 of “Zip for .NET”.
My code looks like this:
Xceed.Zip.Licenser.LicenseKey = “…”;
Xceed.Zip.QuickZip.Unzip(zipFile, dir, true, true, true, “*”);
If a read-only file exists, I always get the following exception:
Cannot perform the requested operation on an item that has the read-only attribute.
Type: Xceed.FileSystem.DiskFile FullName: <path of read-only file>,
at Xceed.FileSystem.AbstractFolder.CopyFilesTo(FileSystemEvents events, Object userData, AbstractFolder destinationFolder, Boolean recursive, Boolean replaceExistingFiles, Object filters)
at Xceed.Zip.QuickZip.Unzip(String zipFileName, String destinationFolder, String decryptionPassword, Boolean replaceExistingFiles, Boolean recursive, Boolean preservePaths, DiskRequiredCallback diskRequiredCallback, Object userParams, String filesToUnzip)
Thanks a lot for any help,
Imported from legacy forums. Posted by Martin (had 2955 views)User (Old forums)MemberFebruary 12, 2007 at 3:07 pmPost count: 23064
You will need to use the FileSystem classes to accomplish this.
What you need to do is to is use the CopyFilesTo() method on ZipArchive, and on the ItemException event, verify if it is a ReadOnly exception, and if so, change the destination file’s attribute before trying to copy the file again, so that the exception is not raised.
events.ItemException += new ItemExceptionEventHandler(events_ItemException);
AbstractFile zip = new DiskFile( @”D:\Temp\someFile.zip” );
ZipArchive archive = new ZipArchive( zip );
AbstractFolder destinationFolder = new DiskFolder( @”D:\temp\destination” );
archive.CopyFilesTo( events, null, destinationFolder, true, true );
private static void events_ItemException(object sender, ItemExceptionEventArgs e)
if( e.Exception is ItemIsReadOnlyException)
e.TargetItem.Attributes = FileAttributes.Normal;
e.Action = ItemExceptionAction.Retry;
Imported from legacy forums. Posted by André (had 3198 views)
- You must be logged in to reply to this topic.