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 free5 Answers, 1 is accepted
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
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 UsingThank you.
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
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.
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