Sunday 27 October 2013

How to create a Zip file with the .NET 4.5

Hi friends,

In this article i will tell you how to create a Zip file with .Net 4.5

In .Net  4.5 , there is new Namespace has been added System.IO.Compression namespace. Now, in a very simple manner, we can perform zip and unzip actions.I will demonstrate how to perform  zip file in C# you can use the following code:

public void CreateZipFile()
    string zipPath = @"C:\";
    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()))

The System.IO.Compression namespace in .NET 4.5 provides us with an easy way to work with zip files. We can create archives, update archives, and extract archives.

I hope you found this article helpful. As always, I appreciate your feedback.

Happy Programming!! 

 If you have any query mail me to


 Sujeet Bhujbal  


No comments:

Post a Comment