Click here to Skip to main content
15,888,984 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi, Is it possible to extract a file with the FileZip class even if the file already exist? atm i'm getting an error when extracting my zip file that the file does already exist.

C#
ZipFile.ExtractToDirectory(Application.StartupPath + @"\patch001.zip", Application.StartupPath);
File.Delete(Application.StartupPath + @"\patch001.zip");
Posted

Hi,

Try to do this:
C#
ZipArchive zipArchive = new ZipFile.OpenRead(Application.StartupPath + @"\patch001.zip");
foreach (ZipArchiveEntry entry in zipArchive.Entries)
{
      entry.ExtractToFile(Application.StartupPath + entry.Name, true);
}
zipArchive.Dispose();

Hope this helps.
 
Share this answer
 
v3
Comments
maxbre 14-Nov-12 13:09pm    
Thanks, but when i'm doing it like that i'm getting this: "Error 1 foreach statement cannot operate on variables of type 'System.IO.Compression.ZipArchive' because 'System.IO.Compression.ZipArchive' does not contain a public definition for 'GetEnumerator'"
Thomas Daniels 14-Nov-12 13:21pm    
I updated my answer.
maxbre 14-Nov-12 13:39pm    
Thanks!
Thomas Daniels 14-Nov-12 13:40pm    
You're welcome!
If the library doesn't have an 'overwrite existing' flag, the easy thing to do, is check and delete it first.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900