tags:

views:

1848

answers:

7

hai how to zip files(Any files or folder ) in vb.net 2005.please give some ideas thank you

by

somu

+1  A: 

Have a look at SharpZipLib

Eoin Campbell
DotNetZip is actively being improved on CodePlex, and simplifies some methods over SharpZipLib.
Gordon Bell
A: 

I do not know how to program in VB.NET. However, a search revealed an interesting link: Zip Compression VB.NET Examples. I hope it will be useful to you.

Alan Haggai Alavi
NB: The examples rely on the commercial Chilkat ZIP library.
Cheeso
A: 

You can use ICSharCode's SharpZipLib library.

Kirtan
A: 

http://www.example-code.com/vbdotnet/vbnetCreateZip.asp

Kthevar
The examples use Chilkat's commercial ZIP library.
Cheeso
A: 

you can take a look here and here

Ahmed Said
+7  A: 

DotNetZip is an easy-to-use, free, open-source library for handling ZIP files in VB.NET and other .NET languages.

Some sample VB.NET code, to create a zip file, adding files one at a time:

Dim ZipToCreate As String = "ex1.zip"
Dim DirectoryToZip As String = "c:\temp"
Using zip As ZipFile = New ZipFile
    Dim filenames As String() = System.IO.Directory.GetFiles(DirectoryToZip)
    Dim filename As String
    For Each filename In filenames
        zip.AddFile(filename)
    Next
    zip.Save(ZipToCreate)
End Using

Or, add files in a group:

Dim ZipToCreate As String = "ex1.zip"
Dim DirectoryToZip As String = "c:\temp"
Dim filenames As String() = System.IO.Directory.GetFiles(DirectoryToZip)
Using zip As ZipFile = New ZipFile
    zip.AddFiles(filenames, "temp")
    zip.Save(ZipToCreate)
End Using

or, Code to zip up an entire directory or folder:

Using zip As ZipFile = New ZipFile
    zip.AddDirectory(directory)
    zip.Save(targetZip)
End Using

Code to extract a zip file:

    Dim ZipFileToExtract As String = "c:\foo.zip"
    Using zip As ZipFile = ZipFile.Read(ZipFileToExtract)
        Dim e As ZipEntry
        For Each e In zip
            ' can conditionally extract here, '
            ' based on name, size, date, whatever.'
            e.Extract
        Next
    End Using

Extract with a progress bar:

Imports Ionic.Zip

Module SimpleUnzip
  Public Sub Unzip(ByVal ZipToUnpack As String, ByVal ExtractDirectory As String)
    Try
      Using zip As ZipFile = ZipFile.Read(ZipToUnpack)
        Form1.ProgressBar1.Maximum = zip.Entries.Count
        Dim entry As ZipEntry
        For Each entry In zip
            Form1.Label1.Text = entry.FileName
            entry.Extract(ExtractDirectory, ExtractExistingFileAction.OverwriteSilently)
            Form1.ProgressBar1.Value = Form1.ProgressBar1.Value + 1
            ' sleep because it's too fast otherwise.
            System.Threading.Thread.Sleep(50)
        Next
        Form1.ProgressBar1.Value = 0
        Form1.Label1.Text = "Done"
      End Using
    Catch ex1 As Exception
      Form1.Label1.Text = ("Exception: " & ex1.ToString())
    End Try
  End Sub
End Module

DotNetZip has progress events for reading, saving, or extracting, so you can power progress bars in ASP.NET or Windows Forms. It does password-protected zip files, Unicode, ZIP64, and self-extracting archives. The zip files it produces are compatible with all other zip tools - WinZip, WinRAR, Windows Explorer, Pkunzip, etc. There's a good help file (online version here) with tons of code examples. There are samples available for download, too.

Cheeso
A: 

You can use our Rebex ZIP component.

Here are some samples of operations you are asking for:

Simple zipping files in one line of code:

' add content of the local directory C:\Data\  '
' to the directory \Data-2010 (within the ZIP archive) '
' (ZIP archive C:\archive.zip doesn't have to exist) 
ZipArchive.Add("C:\archive.zip", "C:\Data\*", "\Data-2010")

Simple unzipping in one line of code:

' extract all *.TXT files from the directory \Data-2010 (within the ZIP file) '
' to the existing local directory C:\Data '
ZipArchive.Extract("C:\archive.zip", "\Data-2010\*.html", "C:\Data")

More samples can be found here.

Jan Šotola