Search code examples
.netzipdotnetzip

dotnetZip How to write to specific folder with memoryStream


I need to create a zip file containing a folder structure and be able to add files from a memory stream to specific folders.

I am trying to achieve this with dotnetZip but they seem to have dropped support for adding a file by stream to a specific folder.

All examples I can find use the following:

zip.AddEntry("test.txt", "folder", memoryStream);

But this method no longer allows you to add a folder name into which to add the file.

zip.AddEntry("test.txt", memoryStream);

How can I use dotnetZip to create a child folder in a zip file and add a memoryStream file to that folder without having to save to disk?


Solution

  • Entry path can include directories inside of archive, so you should first

    .AddEntry("folderName/")

    , next -

    .AddEntry("folderName/filename.txt", memoryStream);