We have two new classes, ZipArchive
and ZipArchiveEntry
, which add the capability to create .zip archives to the .NET framework. This was possible previously, but with several limitations.
Next we will see how to use the ZipArchive
class to create a Zip file and to extract it to a concrete location.
Create a new Visual Studio project of type Console Application named
caZipArchive
.Add the
System.IO.Compression
andSystem.IO.Compression.Filesystem
assemblies as references to the project.Open the Program.cs file and add the following
using
clauses:using System.IO; using System.IO.Compression;
Next, add the following method:
static void CreateZipFile() { String ZipPath= @"C:\PACKT\02-CLR\caZipArchive\test\"; String ZipFilePath = ZipPath + "test.zip"; String FileName01 = "OneTextDocument.txt"; String FileName02 = "OtherTextDocument.txt"; String FileToZip01 = ZipPath + FileName01; String FileToZip02 = ZipPath + FileName02; using...