Question System.IO.Compression difficulties

stulish

Well-known member
Joined
Jun 6, 2013
Messages
61
Programming Experience
3-5
Hi guys i am trying to get the ZipArchive of System.IO.Compression working.

I have used:

VB.NET:
Imports System.IO
Imports System.IO.Compression

and the code is:

VB.NET:
ZipFile.CreateFromDirectory("D:\Temp", "D:\Local", CompressionLevel.Optimal, False)

I keep getting a:

UnauthorizedAccessException was unhandled:

Access to the path 'D:\Local' is denied.

I checked the Drive and Folder permissions and have full access, i then tried writing a text file to the folder and this worked with no problems, is there something i have missed with the CreateFromDirectory to create a zip file of all folders in the temp directory??

Thanks

Stu
 

stulish

Well-known member
Joined
Jun 6, 2013
Messages
61
Programming Experience
3-5
Just realized i haven't given the output file a name LOL, i am getting tired :(

VB.NET:
ZipFile.CreateFromDirectory("D:\Temp", "D:\Local\Output.zip", CompressionLevel.Optimal, False)

Sorry for Posting irrelevant stuff

Stu
 

stulish

Well-known member
Joined
Jun 6, 2013
Messages
61
Programming Experience
3-5
On another point if i wanted to compress the files and save one on a local hard drive and one on a back-up hard drive, would it be better to compress to the local folder and then copy the zipped file to the back up (rather than compress to both locations), i am just thinking that the Zip compression will require more processing than a simple copy. What is the best way to ensure the file is completely zipped before copying??

Thanks

Stu
 

jmcilhinney

VB.NET Forum Moderator
Staff member
Joined
Aug 17, 2004
Messages
14,400
Location
Sydney, Australia
Programming Experience
10+
Yes, you should compress once and then copy the archive. Unless I'm mistaken, CreateFromDirectory is synchronous so the file is completely zipped before it returns.
 
Top Bottom