Click here to Skip to main content
12,300,191 members (55,011 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C#
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.

ZipFile.ExtractToDirectory(Application.StartupPath + @"\patch001.zip", Application.StartupPath);
File.Delete(Application.StartupPath + @"\patch001.zip");
Posted 14-Nov-12 6:06am
maxbre379
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

If the library doesn't have an 'overwrite existing' flag, the easy thing to do, is check and delete it first.
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

Hi,

Try to do this:
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.
  Permalink  
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'"
ProgramFOX 14-Nov-12 13:21pm
   
I updated my answer.
maxbre 14-Nov-12 13:39pm
   
Thanks!
ProgramFOX 14-Nov-12 13:40pm
   
You're welcome!

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160525.2 | Last Updated 14 Nov 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100