-1

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)

AMTraxTGE
  • 65
  • 9
  • You need to start with understanding the error message. Once you figure that out you'll be in a much better position. Error messages do have purpose and meaning. – Sam Axe Feb 15 '15 at 05:34
  • possible duplicate of [What is a NullReferenceException and how do I fix it?](http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) – Bjørn-Roger Kringsjå Feb 15 '15 at 08:18

1 Answers1

0

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.

xpda
  • 15,585
  • 8
  • 51
  • 82
  • Okay yes for some reason the path was wrong. I figured that Forward Slashes would work, but I switched to backslashes and it worked 100%. I did not know that mattered because I have used forward slashes before. – AMTraxTGE Feb 15 '15 at 21:27