Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2105
  • Last Modified:

unzip .zip folder programatically using C#

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


Kind regards,
Pooja
0
poojasureshkumar
Asked:
poojasureshkumar
1 Solution
 
poojasureshkumarAuthor Commented:
Hi,
Am using C# WPF  vs2010 .

Kind regards,
Pooja
0
NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

 
Jaime OlivaresSoftware ArchitectCommented:
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
0
 
poojasureshkumarAuthor Commented:
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
0
 
poojasureshkumarAuthor Commented:
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
0
 
Éric MoreauSenior .Net ConsultantCommented:
>>I tried the link. It is not working .

what is not working? any error?
0
 
poojasureshkumarAuthor Commented:
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
0
 
jonnidipCommented:
If you cannot "use 3rd party dlls" you can get "3rd party code" from SharpZipLib.
You can take this code in a new project and add it to your solution.
I did this way and it works as if I had the .dll referenced.
Please note that this library has also a "FastZip" class that can let you extract all the files of a .zip without looping each item.


Regards.
0

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now