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);
            }
        }
    }
}

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.