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:
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:\Test.zip";
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.ZipArchi ve(zipToOpen, System.IO.Compression.ZipArchi veMode.Create))
{
System.IO.Compression.ZipArchi veEntry readmeEntry = archive.CreateEntry(entryName) ;
using (var writer = new System.IO.StreamWriter( readmeEntry.Open()))
{
writer.Write(content);
}
}
}
}
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@gmail.com
Regards
Sujeet Bhujbal
-------------------------------------------------------------------------------------------------
Personal Website :-http://sujitbhujbal.wordpress.com/
Facebook :-www.facebook.com/sujit.bhujbal
CodeProject:-http://www.codeproject.com/Members/Sujit-Bhujbal
Linkedin :-http://in.linkedin.com/in/sujitbhujbal
Stack-Exchange: http://stackexchange.com/users/469811/sujit-bhujbal
Twitter :-http://twitter.com/SujeetBhujbal
JavaTalks :-http://www.javatalks.com/Blogger/sujit9923/
---------------------------------------------------------------------------------------------------