This project is read-only.

Test for existence of files in an archive

May 28, 2008 at 12:12 AM

Someone added a Work Item saying:

Something came up when I tried to add files that were already into another zip archive: I've got an exception saying that the file already exists in the zip archive, but I can't find a way to test this before trying to add the file to the existing zip archive.

But when I try to add new files to an existing zip file, it returns me an exception and deletes the original zip file without creating a new one. Is there some way to append new files to the existing zip file one?

The way to test for the existence of a file in the archive is this:

      using (ZipFile zip = new ZipFile(ZipFileName))
        ZipEntry e = zip[Candidate];
        if (e==null)
          Console.WriteLine("The file, '{0}', does not exist in the zip archive '{1}'",
          Console.WriteLine("The file '{0}' already exists in the zip archive '{1}'",


Currently there is no way to Update a file in the zip - to update the content of a file already present in the zip. That sounds like a good feature request.

May 29, 2008 at 6:03 PM
Edited Jun 11, 2008 at 7:49 PM
This feature - Updating a file in an archive - is now available in the v1.5 Preview release.
See the UpdateFile() method, or the AddOrUpdateFile() UpdateItem() method on the ZipFile class.