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.
Asked
Active
Viewed 1.4k times
2 Answers
52
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);
}

Martin
- 39,569
- 20
- 99
- 130
-
Hehe, we all do it from time to time. – Martin Jun 22 '11 at 10:43
3
var zip = new ZipFile(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "test.zip"));
var e = zip.AddFile(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "testfile.pdf"), "/");
e.FileName = "PewPewGotcha.pdf";
zip.Save();
Once the ZipFile is saved, the name is updated.

Bob G
- 1,226
- 2
- 16
- 24