Posts

Showing posts with the label zip

Creating a zip archive in C#

Image
StackOverflow link where I got this technique from is here: https://stackoverflow.com/questions/2454956/create-normal-zip-file-programmatically/ First create a new console application: Add references to System.IO.Compression and System.IO.Compression.FileSystem: Select a folder containing a set of files that you would like to archive. You could make this more sophisticated and create your own list of file paths, but I'm just keeping things simple for now: Here is the sample code I use to test the .NET compression library Program.cs [code language="csharp"] using System.IO; using System.IO.Compression; namespace ZipArchive { class Program { static void Main(string[] args) { var zipFile = @"C:\data\myzip.zip"; var files = Directory.GetFiles(@"c:\data"); using (var archive = ZipFile.Open(zipFile, ZipArchiveMode.Create)) { foreach (var fPath in files) ...