Automate Unzip Function

wonder_gal

Active member
Joined
Jun 5, 2006
Messages
34
Programming Experience
1-3
Hi,

I am writing a function to unzip a zipped file, using OpenFileDialog method. Below is my coding, may I know how can I automate my unzip function, means pre-select the zipped file(without having to pop up the directory prompt to let user select the location of the zip file)? Is there any way to accomplish this task?

VB.NET:
With OpenZIPFileDialog
            .InitialDirectory = strFullDirectoryPath
            .Filter = "Zip Files (*.zip)|*.zip*"
            .FilterIndex = 1

            If .ShowDialog() = DialogResult.OK Then
                Dim x As New ICSharpCode.SharpZipLib.Zip.FastZip
                x.ExtractZip(.FileName, strFullDirectoryPath, "csv;xsl")
            End If
End With
 
Hi all,

I've figured out on how to pre-select the zipped file from a specified directory, but I'm getting this error, "Cast from string "C:\temp\FileName.zip" to type 'Integer' is not valid."

Below is my coding, I got this error in the bold line. May I know what does the casting error mean here? Why do I need to cast the string of my zip file path to integer?

VB.NET:
ExtractZIPfiles(Directory.GetFiles(strFullDirectoryPath, "*.Zip"))

Private Sub ExtractZIPfiles(ByVal pathList() As String)
        Dim x As New ICSharpCode.SharpZipLib.Zip.FastZip
        Dim strFullDirectoryPath As String = Path.GetFullPath("C:\temp")

        For Each s As String In pathList

            [B]x.ExtractZip(pathList(s), strFullDirectoryPath, "csv;xsl")[/B]

            MsgBox("Congratulations, your file have been unzipped!", MsgBoxStyle.Information, "Sucessfully Unzipped")
        Next
    End Sub
 
You creates s as a string in the loop.... but then try to use it as the index value to the array (which is expecting an integer, not a string).... Since s already has the text from the pathList.... it should be this:
x.ExtractZip(s, strFullDirectoryPath, "csv;xsl")

-tg
 
Back
Top