Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to zip files/directories in VB.NET?

Tags:

c#

.net

vb.net

zip

I would like to zip a folder containing files and subfolders in VB.NET. My solution targets .NET 4.0 Client Profile.

I see that there is a ZipFile class for .NET 4.5, and System.IO.Packing for .NET 4.0 (but not Client Profile). So, those won't help. I note that there is also a GZipStream class, but I never see .gz files floating around, so not sure if that's a good approach. I would prefer a basic .zip file that I know my users can work with.

There are a handful of third-party solutions, such as http://icsharpcode.github.io/SharpZipLib/, but I assume they are far more bloated than the 10-20 lines of code I am looking for. Maybe that's the right answer...I don't know.

Just hoping for a few lines of VB.NET code to zip some files in a solution targeting .NET 4.0 CP.

like image 658
OfficeAddinDev Avatar asked Oct 21 '25 20:10

OfficeAddinDev


1 Answers

Create ZIP from "source" folder.

Imports System.IO.Compression    
ZipFile.CreateFromDirectory("source","destination.zip",CompressionLevel.Optimal,False)

Extract ZIP to "destination" folder.

ZipFile.ExtractToDirectory("destination.zip","destination")
like image 132
Naitik Patel Avatar answered Oct 23 '25 11:10

Naitik Patel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!