我正在尝试使用Shell32.dll来解压缩一个简单的压缩文件。我有一个对Shell32.dll的引用,它在我的开发PC(Win7 64)上显示为Interop.Shell.dll。我通过文件副本从中心位置推出exe更新,我想为.dll执行此操作好。
程序在XP上使用与我在PC上安装的文件相同的文件失败。我尝试使用从XP \ Windows \ System重命名为Interop.Shell.dll的Shell.dll,但我想这将是简单的 - 当我尝试调用dll时,它会收到一个无法加载的错误。
我打开另一种解压方式,使用与平台无关的dll。我通过Process.Start()使用了7Zip,但我想避免在客户端上安装/更新程序。
是否有一个共同的分母Shell32.dll我可以使用在XP上/之后的任何Win OS上运行吗?
如果我使用Shell32.dll,我是否必须为每个操作系统创建单独的版本?
谢谢!
Function Unzip(FilePathofZip As String, DestinationFolder As String) As Boolean
Try
Dim sFile As String = FilePathofZip
' requires referenc to windows.system.shell32.dll
Dim sc As New Shell32.Shell()
If IO.Directory.Exists(DestinationFolder) Then IO.Directory.Delete(DestinationFolder, True)
Application.DoEvents()
IO.Directory.CreateDirectory(DestinationFolder)
'Declare the folder where the files will be extracted
Dim output As Shell32.Folder = sc.NameSpace(DestinationFolder)
If FilePathofZip.EndsWith(".kmz") Then
sFile = FilePathofZip & ".zip"
IO.File.Move(FilePathofZip, sFile)
Application.DoEvents()
End If
'Declare your input zip file as folder
Dim input As Shell32.Folder = sc.NameSpace(sFile)
'Extract the files from the zip file using the CopyHere command .
output.CopyHere(input.Items, 4)
Return True
Catch ex As Exception
MsgBox(ex.Message)
Return False
End Try
End Function
答案 0 :(得分:0)
我切换到DotNetZip。将项目引用添加到Ionic.Zip.Reduced.dll。进口Ionic.Zip
此代码期望从ESRI REST服务下载的.kmz文件,但也应该使用.zip文件。
Function Unzip(FilePathofZip As String, DestinationFolder As String) As Boolean
' extract .kmz files downloaded from ESRI REST services
Try
Dim sFile As String = FilePathofZip
If IO.Directory.Exists(DestinationFolder) Then IO.Directory.Delete(DestinationFolder, True)
Application.DoEvents()
IO.Directory.CreateDirectory(DestinationFolder)
If FilePathofZip.EndsWith(".kmz") Then
sFile = FilePathofZip & ".zip"
IO.File.Move(FilePathofZip, sFile)
Application.DoEvents()
End If
Try
' Using... required
Using zip As ZipFile = ZipFile.Read(sFile)
Dim e As ZipEntry
For Each e In zip
e.Extract(DestinationFolder)
Next
End Using
Catch ex1 As Exception
MsgBox("Problem with compressed file - notify programmers" & vbCrLf & ex1.Message)
Return False
End Try
Return True
Catch ex As Exception
MsgBox(ex.Message)
Return False
End Try
End Function