Click here to Skip to main content
12,897,124 members (52,573 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 + @"\", Application.StartupPath);
File.Delete(Application.StartupPath + @"\");
Posted 14-Nov-12 6:06am
Rate this: bad
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.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2


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

Hope this helps.
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
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.170424.1 | Last Updated 14 Nov 2012
Copyright © CodeProject, 1999-2017
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