使用 IRONZIP 如何在 VB.NET 中提取 Zip 文件 Curtis Chau 更新日期:7月 28, 2025 Download IronZIP NuGet 下載 Start Free Trial Copy for LLMs Copy for LLMs Copy page as Markdown for LLMs Open in ChatGPT Ask ChatGPT about this page Open in Gemini Ask Gemini about this page Open in Grok Ask Grok about this page Open in Perplexity Ask Perplexity about this page Share Share on Facebook Share on X (Twitter) Share on LinkedIn Copy URL Email article 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. How to Extract Zip Files in VB.NET Install IronZIP Library. Use IronZipArchive.ExtractArchiveToDirectory() method to extract ZIP files. Use IronZipArchive.ExtractArchiveToDirectory() method to extract password-protected ZIP files. Use the GetArchiveEntryNames() method to get all the entries of the ZIP file. What is IronZIP? 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. Use Cases of IronZIP Some use cases of IronZIP are: File compression: You can use IronZIP to reduce the size of your files and save disk space or bandwidth. File distribution: You can use IronZIP to bundle multiple files into a single archive, making sharing or transferring them easier. File encryption: You can use IronZIP to protect your files with passwords and permissions, and prevent unauthorized access or modification. File extraction: You can use IronZIP to open and read ZIP files from various sources, such as local files, streams, or URLs, and extract the contents or metadata. File management: You can use IronZIP to manipulate ZIP files, such as adding, deleting, or merging entries, changing compression formats, or validating the integrity of the archive. Getting Started with IronZIP 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. Install IronZIP NuGet Package 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. VB.NET Extract Zip file Now, let's explore a simple way to extract ZIP files using IronZIP: Imports IronZip Module Program Sub Main(args As String()) ' Set paths for the ZIP file and the extraction directory Dim extractPath As String = "D:\ExtractedFiles" Dim zipPath As String = "D:\Docs.zip" ' Extract the ZIP file to the specified directory IronZipArchive.ExtractArchiveToDirectory(zipPath, extractPath) End Sub End Module Imports IronZip Module Program Sub Main(args As String()) ' Set paths for the ZIP file and the extraction directory Dim extractPath As String = "D:\ExtractedFiles" Dim zipPath As String = "D:\Docs.zip" ' Extract the ZIP file to the specified directory IronZipArchive.ExtractArchiveToDirectory(zipPath, extractPath) End Sub End Module VB .NET 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 (“D:\ExtractedFiles”). If different directories are not specified, it will extract files into the default program folder. Output Similarly, we can also extract Tar, GZip, and BZip2 files. Extract all the Files from Password-Protected ZIP Archive To extract all files from a password-protected ZIP archive using IronZIP in VB.NET, we can use the following code snippet: Imports IronZip Module Program Sub Main(args As String()) ' Extract password-protected ZIP archive using a password IronZipArchive.ExtractArchiveToDirectory("PasswordProtectedZip.zip", "extractedDocs", "myPassw0rd") End Sub End Module Imports IronZip Module Program Sub Main(args As String()) ' Extract password-protected ZIP archive using a password IronZipArchive.ExtractArchiveToDirectory("PasswordProtectedZip.zip", "extractedDocs", "myPassw0rd") End Sub End Module VB .NET 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: View Entries of ZIP file 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: Imports IronZip Sub Main(args As String()) ' Specify the ZIP file path Dim startPath As String = "D:\Docs.zip" ' Open the ZIP archive and list entry names Using archive As New IronZipArchive(startPath) Dim names As List(Of String) = archive.GetArchiveEntryNames() ' Print each entry name to the console For Each name As String In names Console.WriteLine(name) Next name End Using End Sub Imports IronZip Sub Main(args As String()) ' Specify the ZIP file path Dim startPath As String = "D:\Docs.zip" ' Open the ZIP archive and list entry names Using archive As New IronZipArchive(startPath) Dim names As List(Of String) = archive.GetArchiveEntryNames() ' Print each entry name to the console For Each name As String In names Console.WriteLine(name) Next name End Using End Sub VB .NET 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. 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 files and folders in the ZIP archive. Conclusion 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. 常見問題解答 如何在 VB.NET 中提取 ZIP 檔案? 您可以使用 IronZIP 的 ExtractArchiveToDirectory() 方法在 VB.NET 中提取 ZIP 檔案。此方法允許您指定 ZIP 檔案路徑和將文件提取到的目標目錄。 IronZIP 可以處理受密碼保護的 ZIP 檔案嗎? 可以,IronZIP 可以處理受密碼保護的 ZIP 檔案。您可以使用 ExtractArchiveToDirectory() 方法並提供密碼參數來成功提取這些文件。 我可以使用哪種方法列出 VB.NET 中 ZIP 檔案的項目? 您可以使用 IronZIP 的 GetArchiveEntryNames() 方法列出 ZIP 檔案中的所有項目。此方法返回一個項目名稱列表,您可以打印或記錄以供參考。 使用 IronZIP 進行 ZIP 檔案管理的好處是什麼? IronZIP 提供易於使用的界面、高效能和廣泛的壓縮與解壓縮功能。它支持文件壓縮以節省空間、通過打包文件進行分發、加密保護安全性,以及像添加或刪除 ZIP 檔案中的項目等文件管理操作。 IronZIP 支援不同的加密算法嗎? 是的,IronZIP 支援多種加密算法,包括 AES-128、AES-256 和傳統加密算法,確保 ZIP 檔案內文件的安全性處理。 有試用版本的 IronZIP 供開發者使用嗎? 有的,IronZIP 提供免費的試用版本,讓開發者能在做出購買決策前探索其功能和能力。 IronZIP 可以處理不同的壓縮格式嗎? 是的,IronZIP 支援多類壓縮格式例如 ZIP、Tar、GZip 和 BZip2,提供靈活性以滿足各種文件管理需求。 如何在 VB.NET 專案中安裝 IronZIP? 您可以在 VB.NET 專案中使用 NuGet 套件管理員主控台以命令 Install-Package IronZIP 安裝 IronZIP。 IronZIP 能處理 VB.NET 中不同來源的文件提取嗎? 可以,IronZIP 可以從各種來源提取文件,包括本地文件、資料流或 URL,提供 VB.NET 專案中多樣的提取功能。 Curtis Chau 立即與工程團隊聊天 技術作家 Curtis Chau 擁有卡爾頓大學計算機科學學士學位,專注於前端開發,擅長於 Node.js、TypeScript、JavaScript 和 React。Curtis 熱衷於創建直觀且美觀的用戶界面,喜歡使用現代框架並打造結構良好、視覺吸引人的手冊。除了開發之外,Curtis 對物聯網 (IoT) 有著濃厚的興趣,探索將硬體和軟體結合的創新方式。在閒暇時間,他喜愛遊戲並構建 Discord 機器人,結合科技與創意的樂趣。 相關文章 更新日期 6月 22, 2025 如何在 C# 中將 Zip 存檔提取到目錄 ZIP 文件是一種將多個文件和目錄打包成單個存檔的方便方式。 閱讀更多 更新日期 7月 28, 2025 如何在 C# 中使用密碼壓縮文件 在本文中,我們將探討如何使用 C# 和 IronZIP 庫創建受密碼保護的 ZIP 文件 閱讀更多 更新日期 7月 28, 2025 如何在 C# 中將文件解壓到目錄 無論你在開發Windows 應用程序還是 .NET 項目,了解解壓文件的過程都是非常有價值的 閱讀更多 如何使用 C# 壓縮文件夾中的文件如何在 C# 中使用密碼壓縮文件