none
Can I Open a file from WinZip in the associate app without extracting it? RRS feed

  • Question

  • How open file (doc.docx) from ZIP (D:\myZip.zip) with associated app (Word)?

    I'd like to simulate a "normal." behavior of WinZip that can open a file from
    its container (zip file), so I can edit the file and then save it and the WinZip
    is asking for updating the file.

    So my revised question is: Can I Open a file from WinZip in the associate
    app without extracting it? And I want to suppress the update dialog of WinZip.
    Tuesday, March 24, 2020 8:01 AM

All replies

  • Hello,

    For extracting from zip files use ZipArchive class method ExtractToFile then Process.Start to start the document with the associated application for Word in this case. I've used this and wrote an article with source code here.

    Taken from Microsoft docs

    Imports System.IO
    Imports System.IO.Compression
    
    Module Module1
    
        Sub Main()
            Dim zipPath As String = ".\result.zip"
    
            Console.WriteLine("Provide path where to extract the zip file:")
            Dim extractPath As String = Console.ReadLine()
    
            ' Normalizes the path.
            extractPath = Path.GetFullPath(extractPath)
    
            ' Ensures that the last character on the extraction path
            ' is the directory separator char. 
            ' Without this, a malicious zip file could try to traverse outside of the expected
            ' extraction path.
            If Not extractPath.EndsWith(Path.DirectorySeparatorChar.ToString(), StringComparison.Ordinal) Then
                extractPath += Path.DirectorySeparatorChar
            End If
    
            Using archive As ZipArchive = ZipFile.OpenRead(zipPath)
                For Each entry As ZipArchiveEntry In archive.Entries
                    If entry.FullName.EndsWith(".txt", StringComparison.OrdinalIgnoreCase) Then
    
                        ' Gets the full path to ensure that relative segments are removed.
                        Dim destinationPath As String = Path.GetFullPath(Path.Combine(extractPath, entry.FullName))
                        
                        ' Ordinal match is safest, case-sensitive volumes can be mounted within volumes that
                        ' are case-insensitive.
                        If destinationPath.StartsWith(extractPath, StringComparison.Ordinal) Then 
                            entry.ExtractToFile(destinationPath)
                        End If
    
                    End If
                Next
            End Using
        End Sub
    
    End Module


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Tuesday, March 24, 2020 10:52 AM
    Moderator
  • Dear Karen, thank you for your answer.

    I'm familiar with that code :) but it is not I'm looking for :) :)
    I don't want to extract the file and start the process for opening a file in the associated app.

    I'd like to simulate a "normal." behavior of WinZip that can open a file from its container (zip file), so I can edit the file and then save it and the WinZip is asking for updating the file.

    So my revised question is: Can I Open a file from WinZip in the associate app without extracting it? And I want to suppress the update dialog of WinZip.

    Supplement: maybe it would be done with the 3rd part Zip component?

    Tuesday, March 24, 2020 5:04 PM
  • When WinZip opens a file it first save the file to a temp folder then opens it from the temp folder. When WinZip closes and the document has been closed WinZip deletes the temp file. A deviation is to extract the file contents to a stream via ZipArchiveEntry.Open. With the Open method this may look appealing until you learn options a (1) save it to a temp file, back to were we just came from (2) use Open XML SDK which will dump a great deal of support DLL files into your debug folder just to load from a stream, see simple sample code.

    Third party zip components more likely than not do the exact same thing as WinZip.

    Does help?


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Tuesday, March 24, 2020 5:45 PM
    Moderator
  • Yes, it does :) Thank you for your kindness and your time :)
    Tuesday, March 24, 2020 6:22 PM
  • Can I Open a file from WinZip in the associate app without extracting it?

    Yes, with the Shell.

    (reference to Microsoft Shell Controls and Automation)

    You list files from the .zip (I posted a code recently to do that),

    you find the file you want to open from its Name and you call FolderItem2.InvokeVerb with "Open" verb

    (I tested on Windows 10 by enumerating verbs (FolderItemVerbs) to find "Open" or "&Open" ("&Ouvrir" on my french OS) then invoking it)

    Tuesday, March 24, 2020 6:30 PM
  • Can I Open a file from WinZip in the associate app without extracting it?

    Yes, with the Shell.

    (reference to Microsoft Shell Controls and Automation)

    You list files from the .zip (I posted a code recently to do that),

    you find the file you want to open from its Name and you call FolderItem2.InvokeVerb with "Open" verb

    (I tested on Windows 10 by enumerating verbs (FolderItemVerbs) to find "Open" or "&Open" ("&Ouvrir" on my french OS) then invoking it)

    I can not test this but no matter, knowing streams and such there still has to be a footprint of something to disk which may be learned via Process monitor.

    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Tuesday, March 24, 2020 6:56 PM
    Moderator
  • A test on Windows 10, but by hardcoding "open" in english and french

    (should use localized strings or canonical verbs) =>

           ' Add reference : Microsoft Shell Controls and Automation
            ' Add : Imports Shell32
            Dim objShell As Shell32.Shell = New Shell32.Shell()
            Dim sZipPath As String = "E:\Test\Test.zip"
            Dim sFileToOpen As String = "test.jpg"
            Dim objPathFolder As Shell32.Folder = objShell.[NameSpace](sZipPath)
            For Each objFolderItem As Shell32.FolderItem2 In objPathFolder.Items()
                If (objFolderItem.Name = sFileToOpen) Then
                    'Debug.Print(objFolderItem.Verbs.Count.ToString())
                    Dim objItemVerbs As FolderItemVerbs = objFolderItem.Verbs
                    If (Not objItemVerbs Is Nothing) Then
                        For Each objVerb As FolderItemVerb In objItemVerbs
                            ' Test "Open" in english or french ("&Ouvrir")
                            If (objVerb.Name.ToLower().Contains("open") Or objVerb.Name.ToLower().Contains("ouvrir")) Then
                                objFolderItem.InvokeVerb(objVerb)
                                Exit For
                            End If
                            'Debug.Print(objVerb.Name)
                        Next
                    End If
                    Exit For
                End If
            Next




    • Edited by Castorix31 Tuesday, March 24, 2020 7:36 PM
    Tuesday, March 24, 2020 7:34 PM
  • It's working, but the file is open only Read-only :/ 

    Thanks anyway :)

    Tuesday, March 24, 2020 8:25 PM
  • It's working, but the file is open only Read-only :/ 

    Thanks anyway :)

    Pretty confident that this is not possible, no matter what you try and think works make sure to use Process monitor to validate this. Also my thought is if you were to kill WinZip and then search for temp files in the same time period you will find a file that is a strange name but if renamed and double click on the file it will open your file extracted.

    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Tuesday, March 24, 2020 8:28 PM
    Moderator