Click here to Skip to main content
15,890,579 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
So what i am trying to do is download a zip file from the internet and then extract it, it works perfectly on my computer but when i try it on my other computer it just says this warning: Unhandled exeption has occured in your application. If you click continue, the application will ignore this error etc then it says Unable to cast COM object of type 'system;_ComObject' to interface type "Shell32.Shell" and it goes on like that, i really need to fix this quickly, pls help me?

This is my code to extract the zip file
VB
Dim path As String = Directory.GetCurrentDirectory()
      Dim sc As New Shell32.Shell()
      IO.Directory.CreateDirectory(path & "\extract")
      Dim output As Shell32.Folder = sc.NameSpace(path & "\extract")
      Dim input As Shell32.Folder = sc.NameSpace(path & "\mods.zip")
      output.CopyHere(input.Items, 4)
Posted
Updated 5-Nov-14 6:53am
v2
Comments
Richard Deeming 5-Nov-14 12:39pm    
Since you haven't shown any of your code, we can't tell you how to fix it.

If you change your code to use the built-in ZipFile class[^], you won't get that error.
Member 11202889 5-Nov-14 13:42pm    
How can i do this?

Assuming you're using .NET 4.5, you can use the built-in ZipFile class[^].

Add a reference to the System.IO.Compression.FileSystem assembly, and Import the System.IO.Compression namespace. Then use:
VB.NET
Dim path As String = IO.Directory.GetCurrentDirectory()
Dim zipPath As String = IO.Path.Combine(path, "mods.zip")
If Not IO.File.Exists(zipPath) Then
    Throw New IO.FileNotFoundException(Nothing, zipPath)
End If

Dim extractPath As String = IO.Path.Combine(path, "extract")
If Not IO.Directory.Exists(extractPath) Then
    IO.Directory.CreateDirectory(extractPath)
End If

ZipFile.ExtractToDirectory(zipPath, extractPath)


If you're using .NET 4.0 or earlier, then you can use a third-party library such as SharpZipLib[^] or DotNetZip[^] to extract the file.
 
Share this answer
 
Comments
Member 11202889 5-Nov-14 14:56pm    
Thanks! but at ZipFile.ExtractToDirectory(zipPath, extractPath) it doesn't get the 'zipfile'
Richard Deeming 5-Nov-14 14:57pm    
Have you added the reference to the assembly, and the Imports System.IO.Compression statement at the top of your code file?

Is your project targetting .NET 4.5, or an earlier version?
Member 11202889 5-Nov-14 15:04pm    
nvm it works! you're the best!
Member 11202889 5-Nov-14 15:45pm    
but it only works properly like 50% of the time
Richard Deeming 5-Nov-14 15:46pm    
Define not working properly. Are you getting an error?
How can i do use that zipfile class?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900