Results 1 to 14 of 14

Thread: Error with Code

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2011
    Posts
    73

    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

  2. #2
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    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)
    Please mark you thread resolved using the Thread Tools as shown

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jun 2011
    Posts
    73

    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

  4. #4
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: Error with Code

    Do you have the physical directory with this name F:\New Folder\Testzippingutility ?
    Please mark you thread resolved using the Thread Tools as shown

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jun 2011
    Posts
    73

    Re: Error with Code

    Yes,

    and it contains a zip file.

  6. #6
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    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 ?
    Please mark you thread resolved using the Thread Tools as shown

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Jun 2011
    Posts
    73

    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?

  8. #8
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: Error with Code

    archiveFilenameIn - This should be the name of the zip file name as F:\New Folder\Testzippingutility\Test.zip
    Please mark you thread resolved using the Thread Tools as shown

  9. #9
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Jun 2011
    Posts
    73

    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

  11. #11
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  12. #12

    Thread Starter
    Lively Member
    Join Date
    Jun 2011
    Posts
    73

    Re: Error with Code

    Any sample / example for the code, please..

    Thanks

  13. #13
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: Error with Code

    Hope this helps
    Please mark you thread resolved using the Thread Tools as shown

  14. #14
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Error with Code

    Quote Originally Posted by danasegarane View Post
    Hope this helps
    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width