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 37269
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: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |