Link to home
Start Free TrialLog in
Avatar of suresh pondicherry
suresh pondicherryFlag for United States of America

asked on

unzip .zip folder programatically using C#

Hi,
Anybody help me to unzip the .zip folder programatically using C#.


Kind regards,
Pooja
Avatar of Kyle Abrahams, PMP
Kyle Abrahams, PMP
Flag of United States of America image

Avatar of suresh pondicherry

ASKER

Hi,
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
Hi Emoreau,
I tried the link. It is not working .

string backupLocation = @"c:\Temp\compress\customizedBackup";
            string backupSetLocation = @"c:\Temp\compress\customizedBackup.zip";
            ExtractFromZip(backupSetLocation, 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(pOutputPath, System.IO.Path.GetFileName(pkgPart.Uri.ToString()));
                    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(arrBuffer, 0, intRead);
                                 intRead = stmSource.Read(arrBuffer, 0, arrBuffer.Length);
                   
                            }
                        }
                    }
                }
            }

        }

Kind regards,
Pooja
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
>>I tried the link. It is not working .

what is not working? any error?
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
ASKER CERTIFIED SOLUTION
Avatar of jonnidip
jonnidip
Flag of Italy image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial