我正在尝试使用Shell32.dll来解压缩一个简单的压缩文件。我有一个Shell32.dll的引用,它在我的开发PC(Win7 64)上显示为Interop.Shell.dll。我通过文件副本从中心位置推出exe更新,我也想为.dll做这件事。
该程序在XP上失败,使用的文件与我电脑上安装的文件相同。我尝试使用XP\Windows\System中的Shell.dll重命名为Interop.Shell.dll,但我想这很简单——当我尝试调用dll时,它会出现无法加载的错误。
我也打开了另一种解压方式,它使用了一个与平台无关的dll。我已经通过Process.Start()使用了7Zip,但我想避免在客户端上安装/更新程序。
有没有一个共同的分母Shell32.dll,我可以使用它在XP上/之后的任何Win操作系统上运行?
或者,如果我使用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
我切换到了DotNetZip。将项目引用添加到Ionic.Zip.Rreduced.dll。Imports 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