Click here to Skip to main content
11,645,893 members (75,562 online)
Rate this: bad
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 at 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 at 14-Nov-12 13:21pm
I updated my answer.
maxbre at 14-Nov-12 13:39pm
ProgramFOX at 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
0 OriginalGriff 523
1 514
2 Sergey Alexandrovich Kryukov 503
3 Afzaal Ahmad Zeeshan 368
4 DamithSL 305
0 OriginalGriff 1,143
1 994
2 Sergey Alexandrovich Kryukov 808
3 Afzaal Ahmad Zeeshan 702
4 DamithSL 691

Advertise | Privacy | Mobile
Web01 | 2.8.150731.1 | Last Updated 14 Nov 2012
Copyright © CodeProject, 1999-2015
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