This is a migrated thread and some comments may be shown as answers.

UnZip error

5 Answers 438 Views
ZipLibrary
This is a migrated thread and some comments may be shown as answers.
Guido
Top achievements
Rank 1
Guido asked on 05 Jun 2016, 03:19 PM

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

5 Answers, 1 is accepted

Sort by
0
Nikolay Demirev
Telerik team
answered on 08 Jun 2016, 08:59 AM
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.
0
Guido
Top achievements
Rank 1
answered on 12 Jun 2016, 06:58 AM

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.
0
Nikolay Demirev
Telerik team
answered on 13 Jun 2016, 10:15 AM
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 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.
0
Guido
Top achievements
Rank 1
answered on 13 Jun 2016, 05:13 PM
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.
0
Nikolay Demirev
Telerik team
answered on 16 Jun 2016, 09:03 AM
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 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.
Tags
ZipLibrary
Asked by
Guido
Top achievements
Rank 1
Answers by
Nikolay Demirev
Telerik team
Guido
Top achievements
Rank 1
Share this question
or