TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

<< Back to VBNET

VB.NET ZipFile Example

Use the ZipFile class to compress a directory and expand the compressed file.
ZipFile can compress an entire directory. It then can expand the compressed file into a new directory. We use the CreateFromDirectory and ExtractToDirectory methods. ZipFile is simpler than developing custom methods.File
Example. To use this program, please create a folder called "source" in the same directory as the program executable. You can add files to it. Also make sure that a "destination" folder does not yet exist.

Program: Upon execution, the program will take all the files in the source directory and add them to an archive called "destination.zip".

Then: It will expand "destination.zip" into a folder called "destination". We specify CompressionLevel.Optimal.

VB.NET program that uses ZipFile Imports System.IO.Compression Module Module1 Sub Main() ' Create ZIP from "source" directory (in program folder). ZipFile.CreateFromDirectory("source", "destination.zip", CompressionLevel.Optimal, False) ' Extract ZIP to "destination" folder. ZipFile.ExtractToDirectory("destination.zip", "destination") End Sub End Module
Notes, add reference. You may need to add a reference in Visual Studio before you begin. Go to Add Reference and select System.IO.Compression.FileSystem. ZipFile was not in the older versions of the .NET Framework.
Summary. We used the ZipFile type in the VB.NET language. We compressed all the files in one directory into a single ZIP file. We then expanded that file into the original form. The Optimal compression level helped reduce the size of the archive.
© TheDeveloperBlog.com
The Dev Codes

Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf