Last active
July 4, 2016 11:31
-
-
Save jens1101/56c45be53619fc033b268bcbe3ec177e to your computer and use it in GitHub Desktop.
Adding files to ZIP in C#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function saveFileAsZip(string filePath) { | |
using (ZipFile zip = new ZipFile()) | |
{ | |
//Add string | |
zip.AddEntry("dataset.json", "{ foo: 'bar' }"); | |
//Add file as byte array | |
zip.AddEntry("customName.json", System.IO.File.ReadAllBytes(filePath)); | |
//Add file, preserving path | |
zip.AddFile(filePath); | |
//Add file to zip root | |
zip.AddFile(filePath, ""); | |
//Add file to folder in zip | |
zip.AddFile(filePath, "/folder/bar"); | |
return zip; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment