Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleCompress a folder into a Zip file in Visual Basic 2005
DescriptionThis example shows how to compress a folder into a Zip file in Visual Basic 2005.
KeywordsZip, compress, folder, compress folder, compressed folder, compression, Visual Basic 2005
CategoriesAlgorithms, Miscellany, Files and Directories
 
This is one of the few examples on the VB Helper Web site that usees someone else's class. This example uses the CompressedFolder class by Microsoft MVP Eduardo A. Morcillo (see the code for his email address and Web page).

When you click the Zip button, the program creates a DirectoryInfo object representing the directory you enter in the text box. It adds ".zip" to make the name of the Zip file it will create. The code then creates a CompressedFolder object representing this Zip file. It compresses the folder whose name you entered in the text box into the Zip file. This also adds any subdirectories to the Zip file.

 
Private Sub btnZip_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles btnZip.Click
    Dim di As New DirectoryInfo(txtFolder.Text)
    Dim file_name As String = di.FullName & ".zip"

    Using cf As New CompressedFolder(file_name)
        cf.CompressFile(di.FullName)
    End Using

    MessageBox.Show("Done", "Done", MessageBoxButtons.OK, _
        MessageBoxIcon.Information)
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated