Hi,
I want to know we can zip or unzip files without using any other software?
I am working on vb.net project.
Hi,
I want to know we can zip or unzip files without using any other software?
I am working on vb.net project.
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
Have a look at:
http://infozip.sourceforge.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
It is possible to create zip files using the Shell32 COM object. I think this is the code:
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: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 04:59 PM. Reason: Link removed
Bookmarks