สร้าง zip ไฟล์ด้วย DotNetZip

ติดตั้ง

PM> Install-Package DotNetZip -Version 1.13.7
using Ionic.Zip;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            using (ZipFile zip = new ZipFile())
            {
                zip.AddFile("test/20200420.txt");
                zip.AddFile("test/20200421.txt");
                zip.Save("withpath.zip");
            }

            using (ZipFile zip = new ZipFile())
            {
                zip.AddFile("test/20200420.txt", "");
                zip.AddFile("test/20200421.txt", "");
                zip.Save("onlyfile.zip");
            }

            using (ZipFile zip = new ZipFile())
            {
                zip.AddFile("test/20200420.txt", "log");
                zip.AddFile("test/20200421.txt", "log");
                zip.Save("newpath.zip");
            }
        }
    }
}

withpath.zip จะได้

test/20200420.txt
test/20200421.txt

onlyfile.zip จะได้

20200420.txt
20200421.txt

newpath.zip จะได้

log/20200420.txt
log/20200421.txt