This project is read-only.

addEntry with folder

Dec 14, 2010 at 2:39 PM

in the library I've found the method addFile in which is possibile to add a file in a specific directory path of the archive.

For my purposes, I have to use the other method addEntry: how could I add files with this method in a created directory (addDirectoryByName)?

Thank you,

Dec 17, 2010 at 6:56 PM

Elena, you can use

ZipFile.AddFile(string fileNameOnDisk, string directoryPathInArchive).

The second string parameter specifies the directory within the zip archive, to use for the zipentry after it is added.


Dec 20, 2010 at 4:09 PM

Hi Cheeso,
I've already found that method but it isn't good for my purposes (I think) because I don't write the file on disk: I have to use a stream.

For this reason now I use addEntry method, but with this method I cannot specify the directory... I zip all the files in the root directory, but it isn't so good.

Do I miss something or do something wrong?!


Thanx for your attention,


Dec 21, 2010 at 3:02 PM

yes, I see.

If you use the ZipFile.AddEntry() set of methods, you specify the full path to use for the entry within the zip archive, as the entryName parameter.  There must be two filename parameters in the ZipFile.AddFile() methods, because a user may wish to read from a file at one location on the source filesystem, and then use a different name for the entry name within the zip archive.  No such requirement exists when not using a file as the source of the entry data, as is the case for you.  There is only one name you need to specify: the name used for the entry within the zip archive.

If you read the reference documentation for ZipFile.AddEntry(string,stream) you'll see it describes the entryName parameter as

" The name, including any path, which is shown in the zip file for the added entry. "

Does this help?

Dec 24, 2010 at 10:26 AM

Hi Cheeso, it's very helpful!

Thank you very much, now I solved my problem!!!