Results 1 to 5 of 5

Thread: Zip Unzip a file in vb.net?

  1. #1
    Join Date
    Jan 2009
    Posts
    36

    Zip Unzip a file in vb.net?

    Hi,

    I want to know we can zip or unzip files without using any other software?

    I am working on vb.net project.

  2. #2
    Join Date
    May 2008
    Posts
    2,389

    Re: Zip Unzip a file in vb.net?

    How to create a Zip archive in Visual Basic .NET

    Code:
    ' Simple example to create a Zip file in VB.NET
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    
            Dim zip As New Chilkat.Zip()
    
            ' Anything begins the 30-day trial
            Dim unlocked As Boolean
            unlocked = zip.UnlockComponent("30-day trial")
            If (Not unlocked) Then
                MsgBox(zip.LastErrorText)
                Exit Sub
            End If
    
            zip.NewZip("test.zip")
    
            ' Append a directory tree.  This simply adds disk file references
            ' to the Zip object.  No Zip is created at this point.
            Dim success As Boolean
            success = zip.AppendFiles("tree", True)
            If (Not success) Then
                MsgBox(zip.LastErrorText)
                Exit Sub
            End If
    
            ' Write test.zip
            success = zip.WriteZipAndClose()
            If (Not success) Then
                MsgBox(zip.LastErrorText)
            Else
                MsgBox("Zip created!")
            End If
    
        End Sub

  3. #3
    Join Date
    Jun 2008
    Posts
    97

    Re: Zip Unzip a file in vb.net?


  4. #4
    Join Date
    May 2008
    Posts
    26

    Re: Zip Unzip a file in vb.net?

    Hi

    THIS is test and works fine in vb.net 2005

    1) Create a folder on your c drive and name it Test - like this ! C:\Test
    2) Create a text file "myfile" and place it in C:\Test - like this ! C:\Test\myfile.txt
    3) Create a destination folder your c drive and name it Desti - like this ! C:\Desti
    4) Place a zip file in the folder Desti - like this ! C:\Desti\Mytest.zip

    Code:
       Public Function AddZip() As Boolean
            Try
                Dim sc As Shell32.ShellClass = New Shell32.ShellClass
                Dim SrcFlder As Shell32.Folder = sc.NameSpace("C:\Test\")'Path where your test.txt file is located
                Dim fi As Shell32.FolderItem = SrcFlder.Items.Item("myfile.txt")
                Dim DestFlder As Shell32.Folder = sc.NameSpace("C:\Desti" & "\" & "Mytest.zip")
                DestFlder.CopyHere(fi, 20)
                System.Threading.Thread.Sleep(500)
            Catch ignore As Exception
                Return False
            End Try
            Return True
        End Function

  5. #5
    Join Date
    Feb 2009
    Posts
    1

    Re: Zip Unzip a file in vb.net?

    It is possible to create zip files using the Shell32 COM object. I think this is the code:

    Code:
    Imports System.IO
    Imports Shell32
    
    Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim B(21) As Byte
    B(0) = 80 : B(1) = 75 : B(2) = 5 : B(3) = 6
    File.WriteAllBytes("C:\ZipFile.zip", B)
    Dim SH As New Shell
    Dim SF As Folder = SH.NameSpace("C:\ZipFile.zip")
    Dim DF As Folder = SH.NameSpace("C:\FolderToCompress")
    SF.CopyHere(DF)
    End Sub
    End Class
    So, very possible, but not so friendly or easy. It is much easier to manipulate ZIP files using a third-party library like DotNetZip.

    Code:
         Using zip As ZipFile = New ZipFile()
             zip.AddFile("c:\photos\personal\7440-N49th.png")
             zip.AddFile("c:\Desktop\2005_Annual_Report.pdf")
             zip.AddFile("ReadMe.txt")
             zip.Save("MyZipFile.zip")
         End Using
    Last edited by Gaurav; 25-02-2009 at 04:59 PM. Reason: Link removed

Similar Threads

  1. How to unzip multiple files at once in Linux?
    By Waffle in forum Operating Systems
    Replies: 4
    Last Post: 30-12-2009, 05:10 AM
  2. CAM UnZip : Freeware Unzipper
    By Maximus() in forum Windows Software
    Replies: 2
    Last Post: 25-07-2009, 09:58 PM
  3. How to unzip gz file
    By Ashish Goenkar in forum Windows Software
    Replies: 3
    Last Post: 20-05-2009, 11:24 AM
  4. Vista unzip program association
    By Gina in forum Vista Help
    Replies: 3
    Last Post: 11-09-2008, 08:31 PM
  5. Vista unzip utility
    By RLEckhardt in forum Vista Help
    Replies: 6
    Last Post: 30-05-2007, 11:01 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,135,537.25450 seconds with 17 queries