UnZip error

6 posts, 0 answers
  1. Guido
    Guido avatar
    5 posts
    Member since:
    Apr 2016

    Posted 05 Jun Link to this post

    Hi,

    please help me.

    This is my problem:

    I compress some files with this code

    Try
                Using st As Stream = File.OpenWrite(FileZippato)
                    Using zipArchive As ZipArchive = New ZipArchive(st, ZipArchiveMode.Create, False, Nothing)
                        For Each f As String In FileOrigine
                            Extensions.ZipFile.CreateEntryFromFile(zipArchive, f, Path.GetFileName(f))
                        Next
                    End Using
                End Using

            Catch ex As Exception
                Globale.Log.BoxErrore(ex)
            End Try

    so everything is right

    when I unzip the file with

                Extensions.ZipFile.ExtractToDirectory(FileOrigine, CartellaDestinazione)

    catch this exception "folder access denied".

    of course access to this folder is totally free
  2. Nikolay Demirev
    Admin
    Nikolay Demirev avatar
    103 posts

    Posted 08 Jun Link to this post

    Hello Guido,

    I have tested your case using the following code snippet and everything works fine:
    Dim zipFile As String = "C:\Users\demirev\Desktop\MergeMyLastChangeset.zip"
    Dim sourceFolder As String = "C:\Users\demirev\Desktop\PDF"
    Dim targetFolder As String = "C:\Users\demirev\Desktop\PDF\TestFolder"
     
     
    Using st As Stream = File.OpenWrite(zipFile)
        Using zipArchive As New ZipArchive(st, ZipArchiveMode.Create, False, Nothing)
            For Each f As String In Directory.GetFiles(sourceFolder)
                Telerik.Windows.Zip.Extensions.ZipFile.CreateEntryFromFile(zipArchive, f, Path.GetFileName(f))
            Next
        End Using
    End Using
     
    Using stream As Stream = File.OpenRead(zipFile)
        Using zip As New ZipArchive(stream, ZipArchiveMode.Read, False, Nothing)
            Telerik.Windows.Zip.Extensions.ZipFile.ExtractToDirectory(zip, targetFolder)
        End Using
    End Using

    Could you try it on your end? If it does not work, I suggest you check your directory permissions.

    Regards,
    Nikolay Demirev
    Telerik
    Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms.For more information check out this blog post and share your thoughts.
  3. Guido
    Guido avatar
    5 posts
    Member since:
    Apr 2016

    Posted 12 Jun in reply to Nikolay Demirev Link to this post

    Hello Nikolay,

    with your code is the same: access denied.

    Thepermissions are correct.

    Instead, this code, works fine

                Using st As Stream = File.OpenRead(FileOrigine)
                    Using archive As New ZipArchive(st)
                        For Each e As ZipArchiveEntry In archive.Entries
                            Using sw As Stream = File.Create(Path.Combine(CartellaDestinazione, e.FullName))
                                Dim entryStream As Stream = e.Open()
                                Extensions.ZipFile.CopyStreamTo(entryStream, sw)
                                sw.Flush()
                            End Using

                    End Using

                End Using

    Thank you.
  4. Nikolay Demirev
    Admin
    Nikolay Demirev avatar
    103 posts

    Posted 13 Jun Link to this post

    Hello Guido,

    Could you send us the call stack when the exception occurs?

    Could you try to create folders structure of the ZipArchive manually using Directory.CreateDirectory() method inside the folder where you want to extract the files?

    Regards,
    Nikolay Demirev
    Telerik
    Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms.For more information check out this blog post and share your thoughts.
  5. Guido
    Guido avatar
    5 posts
    Member since:
    Apr 2016

    Posted 13 Jun in reply to Guido Link to this post

    Hello Nikolay.
    this is the coplete code:
        Public Shared Sub UnZipToFolder(ByVal FileOrigine As String, ByVal CartellaDestinazione As String)
            Try
                Directory.CreateDirectory(CartellaDestinazione)

                Using stream As Stream = File.OpenRead(FileOrigine)
                    Using zip As New ZipArchive(stream, ZipArchiveMode.Read, False, Nothing)
                        Extensions.ZipFile.ExtractToDirectory(zip, CartellaDestinazione)
                    End Using
                End Using

            Catch ex As Exception
                Globale.Log.BoxErrore(ex)
            End Try
        End Sub
    and this is the stack trace

    in System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)    
       in System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)    
       in System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)    
       in System.IO.File.Open(String path, FileMode mode, FileAccess access, FileShare share)    
       in Telerik.WinControls.Zip.Extensions.ZipFile.ExtractToFile(ZipArchiveEntry source, String destinationFileName, Boolean overwrite)    
       in Telerik.WinControls.Zip.Extensions.ZipFile.ExtractToDirectory(ZipArchive source, String destinationDirectoryName)    
       in Ut.LibreriaZip.UnZipToFolder(String FileOrigine, String CartellaDestinazione)

    Thank you.
  6. Nikolay Demirev
    Admin
    Nikolay Demirev avatar
    103 posts

    Posted 16 Jun Link to this post

    Hello,

    I have attached sample project containing the exact implementation of the methods you use for extracting the archive, converted from C# to VB. The paths are hard coded, could you change it with the exact paths of your zip file and your folder and test it. This way you would be able to catch the exception for the exact entry which causes it and validate if you can really open a stream with the exact path.

    Regards,
    Nikolay Demirev
    Telerik
    Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms.For more information check out this blog post and share your thoughts.
Back to Top