Creating a zip archive in C#

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

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)
            {
               archive.CreateEntryFromFile(fPath, Path.GetFileName(fPath));
            }
         }
      }
   }
}

On running the program see that the files selected from the chosen directory have been compressed into a single zip file:

Just to test that the files have been properly archived, we extract from the newly created zip file as shown:

So that that original un-compressed files are shown in the myzip/ subfolder as shown:

`