1.In the code below and the large number of files in the archive, should I compress each file since it is added to zip?
The way DotNetZip works is to compress each file as it is added to the archive. Your application does not need to perform compression. DotNetZip does this for you.
or should the Adddirectory method provide the same compression?
Entries added to the zip file through the AddDirectory () method follow the same code path when the zip archive is written as entries added via AddFile (). The file data is compressed, then further encrypted, and then written to a zip file.
unsolicited advice: you do not need to do:
zip.AddProgress += new EventHandler<AddProgressEventArgs>(Zip_AddProgress);
you can just do:
zip.AddProgress += Zip_AddProgress;
How do you determine that compression does not occur?
If you are interested in compression for each record, you can register a SaveProgress event handler. The SaveProgress event is triggered at different times during archive recording, including when saving starts, when DotNetZip starts recording data for one record at different intervals during recording one record after the data recording for each record is completed and after the end of recording all data. These steps are described in the ZipProgressEventType enumeration . When the EventType is Saving_AfterWriteEntry, you can calculate the compression ratio for a particular THAT record.
To make sure that compression does not occur, I suggest that you register such a SaveProgress event and look at the compression ratio.
In addition, as described above, some types of files cannot be compressed. JPG, MPG, MP3, ZIP files and others are not very compressed.
Finally, making a backup can be a lot simpler if you just use the DotNetZip command-line tool. If all you want to do is back up a specific directory, you can use the command line tool (zipit.exe) and not write the program. Using the zipit.exe tool, if you use the -v option, the tool prints progress reports and displays the compression for each record through the mechanism described above. Even if you prefer to write your own program, you can use zipit.exe to verify that compression occurs or not when you use DotNetZip.