使用 IRONZIP 如何在 .NET Core 中解壓文件 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 1. Introduction "Unzip" describes the process of taking files and folders out of a ZIP archive and decompressing them. "Unzip" refers to the process of recovering compressed files or directories back to their original condition, so that they can be accessed and used again after being compressed into a ZIP file. We can add various types of files into zip files like images, TXT files, etc. Users can retrieve the contents of a ZIP archive via unzipping, which is the process of reversing the compression process. Accessing individual files or folders that have been packed together for more effective transmission, storage, or sharing is a popular use for it. After the "unzip" procedure is finished, the files have their original structure and can be read, changed, or used as needed by the user. In this article, we are going to unzip files in the Asp.net core using the IronZIP Archive Library. 2. In Asp.net Core, Unzip File Summary Create a new Asp.net Core project. Install the IronZIP library into the created project. To unzip a file, instantiate the IronArchive class. The ZIP file can be extracted by using the ExtractArchiveToDirectory function. Specify the target file where the unzip file needs to be extracted. 3. IronZIP Library Iron Software created the .NET library IronZIP, which makes it easier to handle and manage ZIP files in .NET applications. It offers tools and features to programmers, so they may interact with ZIP in a variety of ways. These include generating, extracting, compressing, decompressing, encrypting, and modifying files and directories inside the ZIP files. 3.1 Features of IronZIP ZIP File Creation: The ability for .NET apps to produce brand-new ZIP archives from the start. Extraction and Decompression: The capacity to remove files and directories from pre-existing ZIP packages and unzip content. Compression: Provides tools for shrinking files and folders into ZIP archives to make them smaller for transport or storage. Password protection and encryption: To safeguard the contents of ZIP archives, this feature offers the ability to apply password protection and encrypt ZIP files. File manipulation: This allows programmers to add, remove, update, or otherwise work with files and directories inside ZIP packages. Compatibility: Made to function in various .NET settings, compatible with multiple iterations of the framework. Performance Optimization: Targeted at maximizing speed so that .NET programs can manage big ZIP files or datasets more effectively. When managing ZIP files for their applications, developers might find IronZIP a useful tool. Within the .NET framework, it provides a variety of features for working with ZIP archives programmatically, offering simplicity and versatility. For the most recent details on features, capabilities, compatibility, and any new functionality included in later versions, see the official documentation, release notes, or the IronZIP website as software libraries are updated and improved over time. To know more, click here. 3.2 Creating a New Project in Visual Studio Select the File option after launching the Visual Studio program. Choose "new project" and then "Asp.Net core Web App." In the relevant text box, type the project name and choose the file location. Next, click the Create button and choose the necessary .NET Framework version. The chosen application's structure will now be generated by the Visual Studio project. In this instance, ASP.NET MVC is being used. Therefore, we have two options: either utilize the current controller, which allows you to add the code and build/run the application, or create a new one. The library may then be added, and the code tested. 4. IronZIP Package Download 4.1 Using Visual Studio You may install packages directly into your solution using Visual Studio's NuGet Package Manager feature. You may use the snapshot below to access the NuGet Package Manager. It provides a search box that pulls up a NuGet website package list. The screenshot below shows us where to look for the phrase "IronZIP" in the package manager. In the image above, a list of pertinent search terms is displayed. Selecting the required option is required to install the solution package. 4.2 Using the Visual Studio Command-Line In Visual Studio, choose Tools > NuGet Package Manager to see the Package Manager Console. Put the following line in the package manager's terminal tab: Install-Package IronZip Upon downloading and installing into the active project, the package is ready for use. 4.3 Direct download from the NuGet website Using the third way, one may get the NuGet package directly from the website. Navigate there to open the link. Select the download package choice from the menu on the right. Double-click the package once it has been downloaded. On its own, it will install itself. Once more, load the solution and start using it in the project. 4.4 Direct download from the IronZIP website Click on this link to obtain the latest package directly from the website Once downloaded, follow the accompanying procedures to add the package to the project. Select the project with a right-click from the solution window. Select the reference and browse its location when it has been downloaded. Click OK after that to add the reference. 4.5 Unzip Files in the Asp.net core You'll need to provide the file name and destination where you wish to extract the file to use IronZIP in C# to extract a specific file from a ZIP archive. Code sample here: using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; using IronZip; namespace IronPDF_WebApp.Pages { public class IndexModel : PageModel { private readonly ILogger<IndexModel> _logger; public IndexModel(ILogger<IndexModel> logger) { _logger = logger; } public IActionResult OnPost() { try { // Retrieve the uploaded file from the form var file = Request.Form.Files[0]; // Set the file path where the file will be saved string filepath = @"C:\temp\uploads\"; // Save the uploaded file to the specified filepath using (var stream = new FileStream(filepath + file.FileName, FileMode.Create)) { file.CopyToAsync(stream); } // Extract the ZIP archive to the specified directory string extractfile = @"C:\temp\extracted"; IronZipArchive.ExtractArchiveToDirectory(filepath + file.FileName, extractfile); } catch (Exception ex) { // Handle exception and redirect to Error page _logger.LogError(ex, "An error occurred while extracting the ZIP file."); return RedirectToAction("Error"); } return RedirectToAction("Get"); } } } using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; using IronZip; namespace IronPDF_WebApp.Pages { public class IndexModel : PageModel { private readonly ILogger<IndexModel> _logger; public IndexModel(ILogger<IndexModel> logger) { _logger = logger; } public IActionResult OnPost() { try { // Retrieve the uploaded file from the form var file = Request.Form.Files[0]; // Set the file path where the file will be saved string filepath = @"C:\temp\uploads\"; // Save the uploaded file to the specified filepath using (var stream = new FileStream(filepath + file.FileName, FileMode.Create)) { file.CopyToAsync(stream); } // Extract the ZIP archive to the specified directory string extractfile = @"C:\temp\extracted"; IronZipArchive.ExtractArchiveToDirectory(filepath + file.FileName, extractfile); } catch (Exception ex) { // Handle exception and redirect to Error page _logger.LogError(ex, "An error occurred while extracting the ZIP file."); return RedirectToAction("Error"); } return RedirectToAction("Get"); } } } Imports Microsoft.AspNetCore.Mvc Imports Microsoft.AspNetCore.Mvc.RazorPages Imports IronZip Namespace IronPDF_WebApp.Pages Public Class IndexModel Inherits PageModel Private ReadOnly _logger As ILogger(Of IndexModel) Public Sub New(ByVal logger As ILogger(Of IndexModel)) _logger = logger End Sub Public Function OnPost() As IActionResult Try ' Retrieve the uploaded file from the form Dim file = Request.Form.Files(0) ' Set the file path where the file will be saved Dim filepath As String = "C:\temp\uploads\" ' Save the uploaded file to the specified filepath Using stream = New FileStream(filepath & file.FileName, FileMode.Create) file.CopyToAsync(stream) End Using ' Extract the ZIP archive to the specified directory Dim extractfile As String = "C:\temp\extracted" IronZipArchive.ExtractArchiveToDirectory(filepath & file.FileName, extractfile) Catch ex As Exception ' Handle exception and redirect to Error page _logger.LogError(ex, "An error occurred while extracting the ZIP file.") Return RedirectToAction("Error") End Try Return RedirectToAction("Get") End Function End Class End Namespace $vbLabelText $csharpLabel In the above code, make sure that the IronZIP namespace is imported. Included in IronZIP's IronZipArchive class is the ExtractArchiveToDirectory function. This allows us to pass two parameters: the source file system and the unzipping file's path. ZIPArchive zip files can have any number of contents, and contents may be extracted using it and saved to a file-specified directory. The directory path, which is used as the extraction point for the contents of the single ZIP file, is the only parameter required by the ExtractArchiveToDirectory method. To extract all the files to the designated directory, this function internally loops over all the files and directories inside the ZIP package. When an exception arises, such as when the ZIP file is missing or there are problems with the extraction procedure, make sure you handle it carefully. Exceptions may be caught and handled with the use of try-catch blocks. For mass extraction activities, the ExtractArchiveToDirectory method makes extraction easier by managing the extraction of all files and directories within the ZIP archive. Zip files can be created with the help of the IronZIP extension method. To read more about the IronZIP library, click here. 5. Conclusion Developers can handle the compression, extraction, and manipulation of ZIP files with the help of IronZIP, a .NET library designed specifically for managing ZIP files in C# applications. By streamlining intricate procedures and making file operations like extracting particular files, extracting files in bulk, adding entries, and modifying existing archives simpler, IronZIP employs an intuitive API. With this library, developers may improve file management capabilities without having to start from scratch in C# projects. It integrates effortlessly. Thanks to its versatility, ZIP contents may be dynamically altered, with files being added, changed, and removed to suit a variety of application requirements. When dealing with situations like missing or damaged ZIP files, IronZIP's strong exception-handling features guarantee a consistent workflow and make mistake remediation easier. While IronZIP has historically offered a trustworthy solution for managing ZIP files in .NET settings, note that my understanding may not reflect the most recent upgrades. IronZIP's pricing starts at $799 and comes with a free developer version. To know more about the license, we can refer here. For the Iron software product, check here. 常見問題解答 我如何在 ASP.NET Core 中解壓縮文件? 您可以使用 IronZIP 庫在 ASP.NET Core 中解壓縮文件。首先,在 Visual Studio 中通過 NuGet 包管理器安裝 IronZIP,然後使用 IronArchive 類和 ExtractArchiveToDirectory 方法將 ZIP 壓縮包中的文件提取到指定目錄。 IronZIP 處理 ZIP 文件的主要功能是什麼? IronZIP 提供多種功能來處理 ZIP 文件,包括創建、提取、壓縮、加密和操作 ZIP 文件。它支持密碼保護並已經針對性能進行了優化,兼容不同的 .NET 框架。 如何在 C# 項目中安裝 IronZIP? 要在 C# 項目中安裝 IronZIP,請使用 Visual Studio 中的 NuGet 包管理器。搜索 'IronZIP' 並安裝它。或者,使用命令 Install-Package IronZIP 在包管理控制台中安裝。 IronZIP 可以用於加密 ZIP 文件嗎? 可以,IronZIP 可以加密 ZIP 文件。它包含用於密碼保護和加密的工具,以確保 ZIP 壓縮包內容的安全性。 如果在 ASP.NET Core 中解壓縮時遇到錯誤,我該怎麼辦? 如果您在 ZIP 文件解壓縮時遇到錯誤,請使用 IronZIP 的異常處理功能。實施 try-catch 代碼塊以處理錯誤,例如 ZIP 文件丟失或損壞。 IronZIP 是否有免費版供開發者使用? 是的,IronZIP 提供免費的開發者版本,允許您在沒有初始成本的情況下探索其功能,同時還有付費許可。 為什麼我應該在我的 ASP.NET Core 項目中使用 IronZIP 來管理 ZIP 文件? IronZIP 簡化了 ASP.NET Core 項目中的 ZIP 文件管理,提供直觀的 API 來創建、提取和修改 ZIP 壓縮包,增強文件管理能力。 IronZIP 如何處理 ZIP 文件提取? IronZIP 使用 ExtractArchiveToDirectory 方法處理 ZIP 文件提取,從 ZIP 壓縮包中提取所有文件和目錄到指定的目錄路徑,有效管理 ZIP 包中的每個元素。 創建一個可用於 IronZIP 的新 ASP.NET Core 項目的過程是什麼? 要創建一個用於 IronZIP 的 ASP.NET Core 新項目,請在 Visual Studio 中設置新項目,通過 NuGet 安裝 IronZIP,並實施 IronArchive 類以使用方法如 ExtractArchiveToDirectory 來管理 ZIP 文件。 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 項目,了解解壓文件的過程都是非常有價值的 閱讀更多 ZipArchive C# (開發者教程)如何在 C# 中打開 Zip 文件