How to zip a file in .NET

It easy to do by use System.IO.Compression.ZipFile using System.IO.Compression; string guid = Guid.NewGuid().ToString(); string fileName = guid + ".json"; using (ZipArchive archive = ZipFile.Open(zipPath, ZipArchiveMode.Create)) { archive.CreateEntryFromFile(fileName, Path.GetFileName(fileName)); } Cheers !

Jan 18, 2025 - 15:28
How to zip a file in .NET

It easy to do by use System.IO.Compression.ZipFile

using System.IO.Compression;
string guid = Guid.NewGuid().ToString();
string fileName = guid + ".json";
using (ZipArchive archive = ZipFile.Open(zipPath, ZipArchiveMode.Create))
        {
            archive.CreateEntryFromFile(fileName, Path.GetFileName(fileName));
        }

Cheers !