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.
Click the file or folder, then press F2. Click the file or folder twice, slowly. Right-click the file or folder and choose Rename from the shortcut menu.
Right-click the file or selection of files, and select Add to zip. Right-click the resulting archive and select Rename. Change the last three letters to a file extension not blocked by the attachment filter (for example, txt ), or remove the extension altogether.
Press and hold (or right-click) the file or folder, select (or point to) Send to, and then select Compressed (zipped) folder. A new zipped folder with the same name is created in the same location. To rename it, press and hold (or right-click) the folder, select Rename, and then type the new name.
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); }
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With