Created
December 1, 2012 21:17
-
-
Save msiddiqi/4185157 to your computer and use it in GitHub Desktop.
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
private static void ArchiveFolder(string folderToArchive, string archivedFile) | |
{ | |
Uri folderToArchiveUri = new Uri(folderToArchive); | |
var filesToArchive = Directory.EnumerateFiles(folderToArchive, "*.*", SearchOption.AllDirectories); | |
using (var fs = new FileStream(archivedFile, FileMode.Create, FileAccess.ReadWrite)) | |
{ | |
using (var archive = new ZipArchive(fs, ZipArchiveMode.Create)) | |
{ | |
filesToArchive | |
.ToList() | |
.ForEach( | |
file => | |
{ | |
var fileName = Path.GetFileName(file); | |
archive.CreateEntryFromFile(file, fileName); | |
}); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment