vb.netunzipshell32

Unzipping A file in vb


I get exception when I try to unzip a file

When I remove the try I receive:

Additional information: Object reference not set to an instance of an object.

    Try
        Dim sc As New Shell32.Shell()
        '
        'Create directory in which you will unzip your files .
        '
        IO.Directory.CreateDirectory(Application.StartupPath & "/Packs/SkyNet/mods")
        '
        'Declare the folder where the files will be extracted
        '
        Dim output As Shell32.Folder = sc.NameSpace(Application.StartupPath & "/Packs/SkyNet/mods")
        '
        'Declare your input zip file as folder  .
        '
        Dim input As Shell32.Folder = sc.NameSpace(Application.StartupPath & "/Downloads/SkyNet.zip")
        '
        'Extract the files from the zip file using the CopyHere command .
        '
        output.CopyHere(input.Items, 4)
        My.Computer.FileSystem.WriteAllText(Application.StartupPath & "/Config/SkyNet.pack", "SkyNet Installed", False)
    Catch ex As Exception
        MessageBox.Show("Could Not Extract Pack: SkyNet", "SkyNet Launcher: Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
        My.Computer.FileSystem.WriteAllText(Application.StartupPath & "/Config/SkyNet.pack", "SkyNet Not Installed", False)
    End Try

I have tried setting output.CopyHere(input.Items, 4) to output.CopyHere(input.Items, 148) but returns same error.

(148 is the number of items inside the zip)


Solution

  • If the path is invalid for the input or output folder, it will cause this error. Check your paths before using them in the dim statement.