Click here to Skip to main content
15,889,878 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
How do you modify or add files to an existing Zip file using C#?

Do you have to extract everything in that zip file and then remake the zip with the old files and new files?
Posted
Comments
Pete O'Hanlon 3-Jun-11 8:08am    
My apologies for not rating this question sooner. It's an excellent question, so have a 5.

1 solution

If you use SharpZipLib[^], you can use the following extension method:
C#
public static void UpdateZip(this ZipFile zipFile, List<string> files)
{
  zipFile.BeginUpdate();
  foreach(string file in files)
  {
    if (File.Exists(file))
    {
      zipFile.Add(file);
    }
  }
  zipFile.CommitUpdate();
  zipFile.Close();
}
To call it, all you need do is:
C#
List<string> myList = new List<string>();
myList.Add(@"c:\temp\myfile.txt");
myList.Add(@"c:\temp\myFile2.txt");
ZipFile zip = new ZipFile("path to file");
zip.UpdateZip(myList);
 
Share this answer
 
v2
Comments
BobJanova 2-Jun-11 12:28pm    
Good link. I recommend SharpZipLib also.
fjdiewornncalwe 2-Jun-11 15:58pm    
My 5. I love that library.

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