Simple way to Zip files with C# .NET (Framework 4.5 /4.6)
using System.IO.Compression;
public void ZipImages()
{
string zipCreatePath = System.Web.Hosting.HostingEnvironment.MapPath("/myZip.zip");
using(ZipArchive archive = ZipFile.Open(zipCreatePath, ZipArchiveMode.Create))
{
List<string> files = new List<string>();
files.Add("wallhaven-103536.jpg");
files.Add("wallhaven-161383.jpg");
files.Add("wallhaven-30764.jpg");
foreach(string file in files)
{
string filePath = System.Web.Hosting.HostingEnvironment.MapPath(string.Format("/images/{0}", file));
archive.CreateEntryFromFile(filePath, file);
}
}
}
Written by Ion D. Filho
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Csharp
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#