Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 21-02-2009
Member
 
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.
Reply With Quote
  #2  
Old 21-02-2009
Member
 
Join Date: May 2008
Posts: 2,383
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
__________________
The FIFA Manager 2009 PC Game
Reply With Quote
  #3  
Old 21-02-2009
Member
 
Join Date: Jun 2008
Posts: 97
Re: Zip Unzip a file in vb.net?

Have a look at:

http://infozip.sourceforge.net/
Reply With Quote
  #4  
Old 21-02-2009
Member
 
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
Reply With Quote
  #5  
Old 23-02-2009
Member
 
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
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Zip Unzip a file in vb.net?"
Thread Thread Starter Forum Replies Last Post
How to unzip multiple files at once in Linux? Waffle Operating Systems 4 30-12-2009 05:10 AM
CAM UnZip : Freeware Unzipper Maximus() Windows Software 2 25-07-2009 09:58 PM
How to unzip gz file Ashish Goenkar Windows Software 3 20-05-2009 11:24 AM
Vista unzip program association Gina Vista Help 3 11-09-2008 08:31 PM
Vista unzip utility RLEckhardt Vista Help 6 30-05-2007 11:01 PM


All times are GMT +5.5. The time now is 09:03 AM.