0

My code is creating archives from csv-files. Some of which are potentially empty. The Problem is, that archives created from empty files are not password protected, although a password is provided. With non empty files it works perfectly well.

As far as i understand this is the intended functionality of DotNetZip, as it checks for zero-length input before applying encryption. However the recipient of the archives needs the files entirely password protected without exception.

This is the code I use:

ZipFile zip;
if (File.Exists(archive)) { zip = ZipFile.Read(archive); }
else { zip = new ZipFile(); }

using (zip)
{
   if (password.Length > 0)
   {
      zip.Password = password;
   }
   zip.AddFile(file, pathInArchive);
   zip.Save(archive);
}

Is there a workaround for this problem?

Ravi B
  • 1,574
  • 2
  • 14
  • 31
Martin
  • 1
  • could you cheat and add a filelist.dat to show the original date/size of any content, that way none of them would be totally empty? – BugFinder Jun 18 '19 at 11:32
  • Processing of the files on the recipients site is completely automated and delivery format can't be easily altered, so i can't add additional files to the archives – Martin Jun 18 '19 at 13:35
  • If there are no files or the files are 0 in length dont make the archive? – BugFinder Jun 18 '19 at 13:59
  • That would be the logical thing to do, however the recipients interface expects a predefined number of files or the whole delivery gets rejected... I think i need to look for a different library... – Martin Jun 18 '19 at 15:03

0 Answers0