suresh pondicherry
asked on
unzip .zip folder programatically using C#
Hi,
Anybody help me to unzip the .zip folder programatically using C#.
Kind regards,
Pooja
Anybody help me to unzip the .zip folder programatically using C#.
Kind regards,
Pooja
http://social.msdn.microsoft.com/Forums/en/csharpgeneral/thread/b5bde5fa-f63a-41e0-8569-c75d2f61e76b
ASKER
Hi,
Am using C# WPF vs2010 .
Kind regards,
Pooja
Am using C# WPF vs2010 .
Kind regards,
Pooja
As an alternative, if the zip file is compressed with the Deflate algorithm, you can use this library: http://www.codeproject.com/Articles/21420/ZipStorer-A-Pure-C-Class-to-Store-Files-in-Zip
ASKER
Hi Emoreau,
I tried the link. It is not working .
string backupLocation = @"c:\Temp\compress\customi zedBackup" ;
string backupSetLocation = @"c:\Temp\compress\customi zedBackup. zip";
ExtractFromZip(backupSetLo cation, backupLocation);
private void ExtractFromZip(string pZipFilename, string pOutputPath)
{
using ( Package pkgMain = Package.Open(pZipFilename, FileMode.Open, FileAccess.Read))
{
foreach (PackagePart pkgPart in pkgMain.GetParts())
{
string strTarget =System.IO.Path.Combine(pO utputPath, System.IO.Path.GetFileName (pkgPart.U ri.ToStrin g()));
using(Stream stmSource = pkgPart.GetStream(FileMode .Open, FileAccess.Read))
{
using(Stream stmDestination = File.OpenWrite(strTarget))
{
byte[] arrBuffer = new byte[10000];
int intRead ;
intRead = stmSource.Read(arrBuffer, 0, arrBuffer.Length);
while(intRead > 0)
{
stmDestination.Write(arrBu ffer, 0, intRead);
intRead = stmSource.Read(arrBuffer, 0, arrBuffer.Length);
}
}
}
}
}
}
Kind regards,
Pooja
I tried the link. It is not working .
string backupLocation = @"c:\Temp\compress\customi
string backupSetLocation = @"c:\Temp\compress\customi
ExtractFromZip(backupSetLo
private void ExtractFromZip(string pZipFilename, string pOutputPath)
{
using ( Package pkgMain = Package.Open(pZipFilename,
{
foreach (PackagePart pkgPart in pkgMain.GetParts())
{
string strTarget =System.IO.Path.Combine(pO
using(Stream stmSource = pkgPart.GetStream(FileMode
{
using(Stream stmDestination = File.OpenWrite(strTarget))
{
byte[] arrBuffer = new byte[10000];
int intRead ;
intRead = stmSource.Read(arrBuffer, 0, arrBuffer.Length);
while(intRead > 0)
{
stmDestination.Write(arrBu
intRead = stmSource.Read(arrBuffer, 0, arrBuffer.Length);
}
}
}
}
}
}
Kind regards,
Pooja
ASKER
Hi jaime_olivares,
Thanks for the link, but i don't want to use 3rd party lib. Also i am using c#, VS2010,
Kind regards,
Pooja
Thanks for the link, but i don't want to use 3rd party lib. Also i am using c#, VS2010,
Kind regards,
Pooja
>>I tried the link. It is not working .
what is not working? any error?
what is not working? any error?
ASKER
Hi Emoreau,
I posted the code earlier. I don't want to use any third party control in the first place. Also i checked the link and applied the logic. It didn't throw any error, but it write all the compressed files in one file.
Kind regards,
Pooja
I posted the code earlier. I don't want to use any third party control in the first place. Also i checked the link and applied the logic. It didn't throw any error, but it write all the compressed files in one file.
Kind regards,
Pooja
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.