0

I'm currently trying to add a folder to a preexisting zip folder in C#. However, I do not know how I would go about this. I've tried using utilities like Aspose.Zip, however, that overwrites the zip file. Here's the current function I have that uses Aspose.Zip:

    public static void addFolderToZipFile(string zipName, string folderPath)
    {
        using(FileStream file = File.Open(zipName, FileMode.Open, FileAccess.ReadWrite))
        {
            using(Archive archive = new Archive())
            {
                DirectoryInfo info = new DirectoryInfo(@folderPath);
                archive.CreateEntries(info);
                archive.Save(file);
                archive.Dispose();
                file.Dispose();
            }
        }
    }

Any ideas? Thanks.

nomes1998
  • 3
  • 1
  • 2
  • `ZipFile.Open("...", ZipArchiveMode.Update)`? – Jeremy Lakeman May 31 '22 at 01:45
  • @JeremyLakeman I have tried this, however, I really don't know how I could add said preexisting folder into the zip file using this method. I've looked online and I haven't really seen anything. However, I am still willing to use this method. – nomes1998 May 31 '22 at 01:59
  • Opening the zip file this way should preserve all existing entries – Jeremy Lakeman May 31 '22 at 02:02

0 Answers0