-
Error with Code
Hi,
I have the following error due to the highlighted text in the code;
'Argumnet not specified for parameter 'outfolder' of 'Public Sub ExtractZipFile(archiveFilenameIn As String, password As String, outFolder As String)'
Code:
Private Sub btnUnpackFolder_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUnpackFolder.Click
ExtractZipFile(Label1.Text, Label2.Text)
End Sub
The function ExtractZipFile is shown below;
Code:
Public Sub ExtractZipFile(ByVal archiveFilenameIn As String, ByVal password As String, ByVal outFolder As String)
Dim zf As ZipFile = Nothing
Try
Dim fs As FileStream = File.OpenRead(archiveFilenameIn)
zf = New ZipFile(fs)
If Not [String].IsNullOrEmpty(password) Then ' AES encrypted entries are handled automatically
zf.Password = password
End If
For Each zipEntry As ZipEntry In zf
If Not zipEntry.IsFile Then ' Ignore directories
Continue For
End If
Dim entryFileName As [String] = zipEntry.Name
' to remove the folder from the entry:- entryFileName = Path.GetFileName(entryFileName);
' Optionally match entrynames against a selection list here to skip as desired.
' The unpacked length is available in the zipEntry.Size property.
Dim buffer As Byte() = New Byte(4095) {} ' 4K is optimum
Dim zipStream As Stream = zf.GetInputStream(zipEntry)
' Manipulate the output filename here as desired.
Dim fullZipToPath As [String] = Path.Combine(outFolder, entryFileName)
Dim directoryName As String = Path.GetDirectoryName(fullZipToPath)
If directoryName.Length > 0 Then
Directory.CreateDirectory(directoryName)
End If
' Unzip file in buffered chunks. This is just as fast as unpacking to a buffer the full size
' of the file, but does not waste memory.
' The "Using" will close the stream even if an exception occurs.
Using streamWriter As FileStream = File.Create(fullZipToPath)
StreamUtils.Copy(zipStream, streamWriter, buffer)
End Using
Next
Finally
If zf IsNot Nothing Then
zf.IsStreamOwner = True ' Makes close also shut the underlying stream
' Ensure we release resources
zf.Close()
End If
End Try
End Sub
How can I remove the error....
Many thanks
-
Re: Error with Code
This function
Public Sub ExtractZipFile(ByVal archiveFilenameIn As String, ByVal password As String, ByVal outFolder As String)
Expect three paramters archiveFilenameIn ,password and outFolder
You are missing one paramter outFolder
ExtractZipFile(Label1.Text, Label2.Text,Label3.Text)
-
Re: Error with Code
Ok, Resolved that problem by removing (ByVal password As String,) and
Code:
If Not [String].IsNullOrEmpty(password) Then ' AES encrypted entries are handled automatically
zf.Password = password
End If
As I don't need a password parameter.
Now, I have no errors but when I execute I receive the Error when I click the btnUnpackFolder -
UnauthorisedAccessExceptional was unhandled
Access to path
'F:\New Folder\Testzippingutility' is denied
on the ExtractZipFile the following line of coded is highlighed as erroneous
Code:
Dim fs As FileStream = File.OpenRead(archiveFilenameIn)
Please note:
Label1 populated with the path: F:\New Folder\Testzippingutility
Label2 populated with the path: F:\New Folder\Testzippingutility2
What am trying to do is- unzip files from Testzippingutility folder and store the results in Testzippingutility2 folder. Using the ExtractZipFile function..
Any help please....
(I think ExtractZipFile is trying to unzip a file rather than a folder - any help with the change please)
Many thanks
-
Re: Error with Code
Do you have the physical directory with this name F:\New Folder\Testzippingutility ?
-
Re: Error with Code
Yes,
and it contains a zip file.
-
Re: Error with Code
Check this file name
Dim fs As FileStream = File.OpenRead(archiveFilenameIn)
archiveFilenameIn - This should be file not directory... What component you use for zipping ?
-
Re: Error with Code
am using the SharpZipLib..
I think at the Dim I should be zipping the folder rather than the filename?
isnt that correct?
-
Re: Error with Code
archiveFilenameIn - This should be the name of the zip file name as F:\New Folder\Testzippingutility\Test.zip
-
Re: Error with Code
the folder isn't a zip archive... it CONTAINS a zip archive file. You need to unzip the FILE... archiveFilenameIn should be the path to the FILE, not the folder. It even says FILENAME right in the variable name. That should be a clue.
Why are you trying to unzip the folder rather than the file?
-tg
-
Re: Error with Code
Ok. let me explain..
I'll have a folder which will contain at one time 100-200 zips files, I need the tool to read all these files from the folder, unzip them and copy over to another folder..
Thats my primarily objective..
Any help how I can achieve this..
Note: Am using SharpZipLib and working with Vb.Net 2005..
Thanks
-
Re: Error with Code
you do it by using the Directory class, calling the GetFiles method, which will return an array of string of the files in the folder, loop through each one, and unzip each file one by one.
It's that simple.
-tg
-
Re: Error with Code
Any sample / example for the code, please..
Thanks
-
Re: Error with Code
-
Re: Error with Code
Quote:
Originally Posted by
danasegarane
Unzipping the file doesn't seem to be the problem... the code he has will do that... if he would supply a filename rather than a directory to unzip.
@abdallahr -
Step 1 - Search MSDN for Directory.GetFiles ... http://social.msdn.microsoft.com/Sea....GetFiles&ac=3
Step 2 - Look at the documentation for Directory.GetFiles - http://msdn.microsoft.com/en-us/library/07wt70x2.aspx
Step 3 - After reading what the method does... scroll down for an example
Step 4 - UNDERSTAND the sample code
Step 5 - Integrate it with your app
-tg