DotNetZip - rename file entry in zip file while compressing

SFun28 picture SFun28 · Jun 20, 2011 · Viewed 12.8k times · Source

Using DotNetZip, is it possible to compress a file such that the zip lists a different file name for a file than the file name on disk? For example, I want to add myFile.txt to a zip file, but I want it to be called otherFile.txt.

Answer

Martin picture Martin · Jun 20, 2011

From the DotNetZip FAQ:

Add an entry, overriding its name in the archive

  using (ZipFile zip1 = new ZipFile())
  {
      zip1.AddFile("myFile.txt").FileName = "otherFile.txt"; 
      zip1.Save(archiveName);
  }