|
| |||||||||
| Tags: file, unzip, vb dot net, zip |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| |||
| |||
| Zip Unzip a file in vb.net? I want to know we can zip or unzip files without using any other software? I am working on vb.net project. |
|
#2
| ||||
| ||||
| 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 |
|
#3
| |||
| |||
| Re: Zip Unzip a file in vb.net? |
|
#4
| ||||
| ||||
| 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
| |||
| |||
| 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
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 03:59 PM. Reason: Link removed |
![]() |
|
| Thread Tools | Search this Thread |
| |
Similar Threads for: "Zip Unzip a file in vb.net?" | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| slow unzip | MS-Adict | Vista Help | 34 | 01-02-2010 07:17 AM |
| How to unzip gz file | Ashish Goenkar | Windows Software | 3 | 20-05-2009 11:24 AM |
| Associate unzip file attribute in Vista | LiveAndLearn | Vista Help | 6 | 08-08-2008 03:29 PM |
| .zip error message - Source Path Too Long - How do I unzip my file | Jill | Vista File Management | 4 | 30-03-2008 06:03 AM |
| Vista is taking very long time to unzip file | Raj | Windows Vista Performance | 1 | 25-02-2008 05:54 AM |