Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Getting rid of Interop.Shell32.dll
Message
De
20/07/2010 20:14:31
 
 
À
Tous
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Titre:
Getting rid of Interop.Shell32.dll
Versions des environnements
Environment:
VB 9.0
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01473252
Message ID:
01473252
Vues:
91
It seems with the latest version of .NET that there are some issues with Interop.Shell32.dll. Basically, this one has never been part of the framework. It does not appear in the .NET references but in the COM references. I was using a reference to it to be able to use the Shell approach to zip a file or a directory. This has work. While is doesn't create a fully compliant zip file, it did work for a while.

Later on, I adjusted my zip class to support parallel methods to zip and unzip with Winzip. That assumes that Winzip is installed on where it runs.

Now, in order to avoid all those problems with Shell32, I would like to know if there could be an equivalent of that code so I could use something directly from the framework and not from a COM object:
        ' Zip a file
        Public Function Zip() As Boolean
            Dim lcFile As String = ""
            Dim llSuccess As Boolean = False
            Dim lnReturn As Double = 0
            Dim loByte(21) As Byte
            Dim loObject As Object
            Dim loDestinationFolder As Shell32.Folder
            Dim loFile As Shell32.FolderItem
            Dim loProcess As Framework.ProcessFile = New Framework.ProcessFile(oApp)
            Dim loShellClass As Shell32.ShellClass = New Shell32.ShellClass
            Dim loSourceFolder As Shell32.Folder

            ' Reset everything
            lError = False
            cError = ""

            ' If we want the default
            If Not lWinZip Then

                Try

                    ' If the source folder does not exist
                    If Not oApp.DirectoryExist(cSourceFolder) Then
                        cError = "The directory " + cSourceFolder + " does not exist."
                        lError = True
                        Exit Try
                    End If

                    loSourceFolder = loShellClass.NameSpace(cSourceFolder)

                    loByte(0) = 80 : loByte(1) = 75 : loByte(2) = 5 : loByte(3) = 6

                    ' Make an empty PKZip file
                    File.WriteAllBytes(cDestinationFile, loByte)

                    loDestinationFolder = loShellClass.NameSpace(cDestinationFile)

                    ' For each file
                    For Each loObject In oFile
                        lcFile = loObject(1)

                        ' If the file does not exist
                        If Not oApp.FileExist(cSourceFolder + "\" + lcFile) Then
                            cError = "The file " + cSourceFolder + "\" + lcFile + " does not exist."

                            ' Remove the temporary file
                            If Not oApp.DeleteFile(cDestinationFile) Then

                            End If

                            lError = True
                            Exit Try
                        End If

                        loFile = loSourceFolder.Items.Item(lcFile)
                        loDestinationFolder.CopyHere(loFile, 20)
                    Next

                    llSuccess = True
                Catch loError As Exception
                    lError = True
                    cError = loError.Message
                End Try

            Else
Basically, the use of ShellClass allows us to zip a file using a shell approach. If someone knows something that I can use directly from the framework instead, that would be appreciated.
Michel Fournier
Level Extreme Inc.
Designer, architect, owner of the Level Extreme Platform
Subscribe to the site at https://www.levelextreme.com/Home/DataEntry?Activator=55&NoStore=303
Subscription benefits https://www.levelextreme.com/Home/ViewPage?Activator=7&ID=52
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform