13 June, 2013
0 Comments
1 category
If you want to create a zip file in C# with the OOB BCL, in C# you can use the following code:
public void CreateZipFile() { string zipPath = @"C:\Test.zip"; string entryName = "Readme.txt"; string content = "Hello world!"; using (var zipToOpen = new System.IO.FileStream(zipPath, System.IO.FileMode.CreateNew)) { using (var archive = new System.IO.Compression.ZipArchive(zipToOpen, System.IO.Compression.ZipArchiveMode.Create)) { System.IO.Compression.ZipArchiveEntry readmeEntry = archive.CreateEntry(entryName); using (var writer = new System.IO.StreamWriter(readmeEntry.Open())) { writer.Write(content); } } } }
Tags: C#
Category: Uncategorized