Test in a live environment
Test in production without watermarks.
Works wherever you need it to.
Zip files are a popular way to compress and package multiple files into a single archive. Working with compressed files, such as ZIP archives, is a common task in software development. In VB.NET, developers often need a reliable and efficient way to extract data from ZIP files. One powerful library that simplifies this process is IronZIP. In this article, we'll explore using IronZIP to extract ZIP files in VB.NET.
IronZipArchive.ExtractArchiveToDirectory()
method to Extract zip file.IronZipArchive.ExtractArchiveToDirectory()
method to Extract Password-Protected zip files.GetArchiveEntryNames()
method to get all the entries of the zip file.IronZIP, a collection of .NET software components for various development needs. IronZIP stands out for its ease of use, performance, and support for a wide range of compression and decompression features.
Some use cases of IronZIP are:
To begin using IronZIP in your VB.NET project, we'll need to install the IronZIP library. We can easily do this by using NuGet Package Manager Console or Visual Studio's NuGet Package Manager.
Write the Following Command in the NuGet Package Manager Console.
Install-Package IronZip
Press Enter to execute the command. NuGet will download and install the IronZIP package along with its dependencies. You'll see output in the console indicating the progress of the installation.
Now, let's explore a simple way to extract ZIP files using IronZIP:
Imports IronZip
Module Program
Sub Main(args As String())
Dim extractpath = "D:\ExtractedFiles"
Dim zippath = "D:\Docs.zip"
IronZipArchive.ExtractArchiveToDirectory(zippath, extractpath)
End Sub
End Module
Imports IronZip
Module Program
Sub Main(args As String())
Dim extractpath = "D:\ExtractedFiles"
Dim zippath = "D:\Docs.zip"
IronZipArchive.ExtractArchiveToDirectory(zippath, extractpath)
End Sub
End Module
We have used the ExtractArchiveToDirectory
method of the IronZipArchive
class, which extracts all the entries from a ZIP archive to a specified directory. It passes two arguments to the method: the path of the ZIP file (“D:\Docs.zip”) and the path of the destination directory (“extracted”). Since we have not specified any directory, therefore it will extract files in the default program folder.
Similarly, we can also extract Tar
, GZip
, and BZip2
files.
To extract all files from a password-protected ZIP archive using IronZIP in VB.NET, we can use the following code snippet.
Imports IronZip
Imports System
Module Program
Sub Main(args As String())
IronZipArchive.ExtractArchiveToDirectory("PasswordProtectedZip.zip", "extractedDocs", "myPassw0rd")
End Sub
End Module
Imports IronZip
Imports System
Module Program
Sub Main(args As String())
IronZipArchive.ExtractArchiveToDirectory("PasswordProtectedZip.zip", "extractedDocs", "myPassw0rd")
End Sub
End Module
'INSTANT VB TODO TASK: The following line uses invalid syntax:
'@Imports IronZip @Imports System Module Program @Sub Main(args @As String()) IronZipArchive.ExtractArchiveToDirectory("PasswordProtectedZip.zip", "extractedDocs", "myPassw0rd") @End @Sub @End Module
The above VB.NET code uses the IronZIP library to extract items of a password-protected ZIP archive. It calls the ExtractArchiveToDirectory
method of the IronZipArchive
class, which extracts all the entries from a ZIP archive to a specified directory. It passes three arguments to the method: the full path of the ZIP file (“PasswordProtectedZip.zip”), the path of the destination directory (“extractedDocs”), and the password of the ZIP file (“myPassw0rd”).
IronZIP supports AES-128, AES-256, and traditional Encryption algorithms. If the password is incorrect or the ZIP file is not encrypted, the method will throw an exception. The extracted files are:
We can view the entries of a compressed file easily by using the IronZIP. The following code opens the ZIP file and displays its entries on the console.
Sub Main(args As String())
Dim startpath = "D:\Docs.zip"
Using archive = New IronZipArchive(startPath)
Dim names As List(Of String) = archive.GetArchiveEntryNames()
For Each name As String In names
Console.WriteLine(name)
Next name
End Using
End Sub
Sub Main(args As String())
Dim startpath = "D:\Docs.zip"
Using archive = New IronZipArchive(startPath)
Dim names As List(Of String) = archive.GetArchiveEntryNames()
For Each name As String In names
Console.WriteLine(name)
Next name
End Using
End Sub
The above Visual Basic .NET code snippet uses the IronZIP library to extract the names of the entries in a ZIP archive. The code does the following:
It creates a new instance of the IronZipArchive
class, passing the path of the ZIP file (“D:\Docs.zip”) as a parameter. We can pass the specific file name in the parameter. This opens the ZIP file and loads its contents into memory. The instance is assigned to a variable named archive and is wrapped in a Using statement, which ensures that the ZIP file is closed and disposed of when the code block ends.
It calls the GetArchiveEntryNames
method of the archive object, which returns a list of strings containing the names of all the entries in the ZIP archive. The list is assigned to a variable named names. It iterates over the names list using a For Each loop and prints each name to the console using the Console.WriteLine
method. This displays the names of the file system and folders in the ZIP archive.
In conclusion, IronZIP emerges as a powerful tool for handling ZIP archives in VB.NET, offering a rich set of features for compression, extraction, and manipulation. Its versatility extends beyond the basics, allowing developers to seamlessly integrate functionalities like password protection, encryption, and efficient file management. By exploring the examples provided, you can unlock the full potential of IronZIP in your VB.NET projects.
As demonstrated, the library simplifies the extraction process, enabling developers to effortlessly handle password-protected ZIP archives, view file entries, and perform various operations with ease. Moreover, IronZIP's compatibility with a range of compression formats and support across multiple platforms makes it a valuable asset for developers working in diverse environments. IronZIP provides a free trial option that aligns perfectly with their requirements.
9 .NET API products for your office documents