Hi,
i want to know how to unzip a zip file and extract the files to a particular location
please help me
thanks in advance
varinder
5 37304
OK, this isn't my code, I found it as an example, so I haven't tested it.
It uses a 3rd party library called SharpZipLib. You will need to download it. It can be registered as an assembly.
Here's some code: - Public Sub ExtractArchive(ByVal zipFilename As String, ByVal ExtractDir As String)
-
Dim Redo As Integer = 1
-
Dim MyZipInputStream As ZipInputStream
-
Dim MyFileStream As FileStream
-
MyZipInputStream = New ZipInputStream(New FileStream(zipFilename, FileMode.Open, FileAccess.Read))
-
Dim MyZipEntry As ZipEntry = MyZipInputStream.GetNextEntry
-
Directory.CreateDirectory(ExtractDir)
-
While Not MyZipEntry Is Nothing
-
If (MyZipEntry.IsDirectory) Then
-
Directory.CreateDirectory(ExtractDir & "\" & MyZipEntry.Name)
-
Else
-
If Not Directory.Exists(ExtractDir & "\" & _
-
Path.GetDirectoryName(MyZipEntry.Name)) Then
-
Directory.CreateDirectory(ExtractDir & "\" & _
-
Path.GetDirectoryName(MyZipEntry.Name))
-
End If
-
MyFileStream = New FileStream(ExtractDir & "\" & _
-
MyZipEntry.Name, FileMode.OpenOrCreate, FileAccess.Write)
-
Dim count As Integer
-
Dim buffer(4096) As Byte
-
count = MyZipInputStream.Read(buffer, 0, 4096)
-
While count > 0
-
MyFileStream.Write(buffer, 0, count)
-
count = MyZipInputStream.Read(buffer, 0, 4096)
-
End While
-
MyFileStream.Close()
-
End If
-
Try
-
MyZipEntry = MyZipInputStream.GetNextEntry
-
Catch ex As Exception
-
MyZipEntry = Nothing
-
End Try
-
End While
-
If Not (MyZipInputStream Is Nothing) Then MyZipInputStream.Close()
-
If Not (MyFileStream Is Nothing) Then MyFileStream.Close()
-
End Sub
you can also set a reference to VJSLIB, it has built in classes for zipping and unzipping files
under XP you can use shell32 directly without 3rd Party software
you have to add the COM reference "Microsoft Shell Controls And Automation" into your Project
see following (handy) sample code: - Imports System.IO
-
Imports Shell32
-
-
---
-
-
Private Sub Button303_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button303.Click
-
-
' Unzip Variables
-
Dim UserShell As Shell32.IShellDispatch2
-
Dim ZipContent As Shell32.FolderItems
-
Dim ExportLocation As Shell32.Folder
-
-
' -----------------------------------------------
-
' Unzip File -> only XP ?!
-
' -----------------------------------------------
-
-
If File.Exists("c:\temp\zipfile.zip") = False Then
-
' error mesage
-
End If
-
-
UserShell = CType(CreateObject("Shell.Application"), IShellDispatch2)
-
-
' if you like, you can get some properties of your content
-
' for ex. filenames?
-
-
ZipContent = UserShell.NameSpace(("c:\temp\zipfile.zip")).Items
-
Dim i As Integer
-
Dim Filename As String
-
For i = 0 To ZipContent.Count - 1
-
Filename = ZipContent.Item(i).Name.ToString
-
Next
-
-
' unpack the thing
-
ExportLocation = UserShell.NameSpace(("c:\temp\"))
-
If ExportLocation IsNot Nothing Then
-
ExportLocation.CopyHere(UserShell.NameSpace(("c:\temp\zipfile.zip")).Items)
-
End If
-
End Sub
-
this is it...
Here's some example code: -
Dim ZipToUnpack As String = "C1P3SML.zip"
-
Dim TargetDir As String = "C1P3SML"
-
Console.WriteLine("Extracting file {0} to {1}", ZipToUnpack, TargetDir)
-
Using zip1 As ZipFile = ZipFile.Read(ZipToUnpack)
-
AddHandler zip1.ExtractProgress, AddressOf MyExtractProgress
-
Dim e As ZipEntry
-
' here, we extract every entry, but we could extract
-
' based on entry name, size, date, etc.
-
For Each e In zip1
-
e.Extract(TargetDir, ExtractExistingFileAction.OverwriteSilently)
-
Next
-
End Using
-
There are some nice options... Progress Events, ZIP passwords, renaming entries in Zip files, ZIP64, AES encryption, lots more. There's a good help file and forums, too.
Many more examples at: http://dotnetzip.codeplex.com/Wiki/V...le=VB-examples
Download DotNetZip at http://dotnetzip.codeplex.com
Free.
Cheeso,
Your example works with .rar files too ???
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Yang |
last post by:
hi guys.
anyone can tell me how to unzip a file using php ?
thank you
|
by: Aurelio |
last post by:
I need to unzip a file from my c# Windows application. is it possible?. How
can i do it?
|
by: Miki Peric |
last post by:
Which .Net function I should use to extract file name from URL/path?
|
by: Jan |
last post by:
Hi,
Is there a way to unzip a file in a directory from C#. I need a program to
do that since that program copies the file from a server to a local machine,
and then has to verify the contents of...
|
by: Jan |
last post by:
Hi,
Is there a way to unzip a file from C# since I need to download a zip file
from the server, unzip it and verify its contents, all through the same
program.
Thanks in advance,
Jan
|
by: fniles |
last post by:
In VB.NET 2003 how can you programmatically unzip a ZIP file ?
Thank you.
|
by: kokilatejas |
last post by:
Hi all
Please kindly help me on this i need to unzip a folder and place the contents in another folder using vb as code .
eg: c:\test as source
c:\test\test1 as destination
Thanks in...
|
by: moroccanplaya |
last post by:
hi i have created a program which creates a file then lets u add other files on to it then it should be able to extract it back out in order. my program can only extract an archive with only one file...
|
by: maheen khan |
last post by:
basically i extracted some attributes of file(name, file type, path etc) present in a directory and listed them in a c++ file, now i want to extract the file path only so that i can use it as an...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |