Programmatically Zip and UnZip the files in .NET
Normally we may find the functionality to Zip and Unzip the file pro grammatically.We have many third party components to do this operation.Here I am going to present Zip and Unzip files using "CGZipLibrary.dll" in C#.NET.
To do this we need to download the CGLibrary.dll from this link and register this dll.
The zip file contains 3 DLL's:
regsvr32 filepath\filename
Ex: regsvr32 D:\Download\CGLibrary.dll
After registering the dll and Copy zip32.dll and unzip32.dll to
c:\windows\system32 directory or c:\winnt\system32.
Unzip the file you need to do like this
string SrcPath = @"D:\StudentReports.zip";
CGZipFiles oZip = new CGZipFiles();
Happy coding :-)
To do this we need to download the CGLibrary.dll from this link and register this dll.
The zip file contains 3 DLL's:
- CGZipLibrary.dll
- zip32.dll
- Unzip32.dll
regsvr32 filepath\filename
Ex: regsvr32 D:\Download\CGLibrary.dll
After registering the dll and Copy zip32.dll and unzip32.dll to
c:\windows\system32 directory or c:\winnt\system32.
Unzip the file you need to do like this
string SrcPath = @"D:\StudentReports.zip";
string DestPath = @"D:\ZippedFiles";
try
{
CGUnzipFiles oUnzip = new CGUnzipFiles();
oUnzip.ZipFileName = SrcPath;
oUnzip.ExtractDir = DestPath;
int result = oUnzip.Unzip();
}
catch (Exception ex)
{
throw ex;
}
Zip the file you need to do like this
oZip.AddFile(@"D\Test1.txt");
oZip.AddFile(@"D\Test2.txt");
oZip.AddFile(@"D\Test3.txt");
oZip.ZipFileName = @"D:\ZippedFiles";
int result= oZip.MakeZipFile();
Like this we can do Zip and Unzip the files programmatically.
Comments
Post a Comment