IronZIP入門指南
IronZIP:您的 .NET 一體化歸檔庫
IronZIP是由 Iron Software 開發的歸檔壓縮和解壓縮函式庫。 除了廣泛使用的 ZIP 格式外,它還可以處理 TAR、GZIP 和 BZIP2 格式。
C# 檔案壓縮和解壓縮程式庫
- 下載 C# 程式庫以進行檔案壓縮和解壓縮
- 支援 ZIP、TAR、GZIP 和 BZIP2 格式
- 可自訂壓縮級別,範圍從 0 到 9
- 從壓縮檔中提取內容
- 將檔案追加到現有 ZIP 壓縮封包並產生新的 ZIP 文件
相容性
IronZIP具有跨平台相容性,支援以下平台:
.NET 版本支援:
- C# 、 VB.NET 、 F#
- .NET 7、6、5和 Core 3.1+
- .NET Standard (2.0+)
- .NET Framework (4.6.2+)
作業系統和環境支援:
- Windows (10+,Server 2016+)
- Linux (Ubuntu、Debian、CentOS 等)
- macOS (10+)
- iOS (12+)
- Android API 21+(v5「棒棒糖」)
- Docker (Windows, Linux, Azure)
- Azure (VPS、WebApp、函數)
- AWS (EC2、Lambda)
.NET 專案類型支援:
- Web (Blazor 和 WebForms)
- 行動裝置 (Xamarin & MAUI)
- 桌面 (WPF & MAUI)
- 控制台 (應用程式 & 程式庫)
安裝
IronZIP庫
若要安裝 IronZIP 軟體包,請在終端機或軟體包管理器控制台中使用以下命令:
或者,從 官方 IronZIP NuGet 網站直接下載。
安裝完畢後,您可以在 C# 程式碼的頂部添加 using IronZip; 進行開始。
應用許可證密鑰
下一步,通過將授權金鑰分配給 License 類的 LicenseKey 屬性,將有效的授權或試用金鑰應用於 IronZIP。 在導入語句之後、使用任何 IronZIP 方法之前,先加入以下程式碼:
using IronZip;
// Apply your license key here
IronZip.License.LicenseKey = "YOUR_LICENSE_KEY";Imports IronZip
' Apply your license key here
IronZip.License.LicenseKey = "YOUR_LICENSE_KEY"Imports IronZip
' Apply your license key here
IronZip.License.LicenseKey = "YOUR_LICENSE_KEY"程式碼範例
建立存檔範例
使用 using 語句建立 ZIP 檔案。 在 using 區塊內,使用 AddArchiveEntry 方法將檔案匯入 ZIP 檔案。最後,使用 SaveAs 方法匯出 ZIP 檔案。
using IronZip;
using System.IO;
class Program
{
static void Main()
{
// Create a new ZIP file
using (var archive = new ZipArchive())
{
// Add a file to the archive
archive.AddArchiveEntry("example.txt", File.ReadAllBytes("path/to/example.txt"));
// Save the ZIP archive
archive.SaveAs("archive.zip");
}
}
}using IronZip;
using System.IO;
class Program
{
static void Main()
{
// Create a new ZIP file
using (var archive = new ZipArchive())
{
// Add a file to the archive
archive.AddArchiveEntry("example.txt", File.ReadAllBytes("path/to/example.txt"));
// Save the ZIP archive
archive.SaveAs("archive.zip");
}
}
}Imports IronZip
Imports System.IO
Friend Class Program
Shared Sub Main()
' Create a new ZIP file
Using archive = New ZipArchive()
' Add a file to the archive
archive.AddArchiveEntry("example.txt", File.ReadAllBytes("path/to/example.txt"))
' Save the ZIP archive
archive.SaveAs("archive.zip")
End Using
End Sub
End ClassImports IronZip
Imports System.IO
Friend Class Program
Shared Sub Main()
' Create a new ZIP file
Using archive = New ZipArchive()
' Add a file to the archive
archive.AddArchiveEntry("example.txt", File.ReadAllBytes("path/to/example.txt"))
' Save the ZIP archive
archive.SaveAs("archive.zip")
End Using
End Sub
End Class將壓縮檔案解壓縮到資料夾
使用 ExtractArchiveToDirectory 方法從 ZIP 檔案中提取內容。 指定目標 ZIP 檔案的路徑和解壓目錄。
using IronZip;
class Program
{
static void Main()
{
// path to the ZIP file and extraction directory
string zipPath = "archive.zip";
string extractPath = "extracted/";
// Extract all files in the ZIP archive to the specified directory
using (var archive = new ZipArchive(zipPath))
{
archive.ExtractArchiveToDirectory(extractPath);
}
}
}using IronZip;
class Program
{
static void Main()
{
// path to the ZIP file and extraction directory
string zipPath = "archive.zip";
string extractPath = "extracted/";
// Extract all files in the ZIP archive to the specified directory
using (var archive = new ZipArchive(zipPath))
{
archive.ExtractArchiveToDirectory(extractPath);
}
}
}Imports IronZip
Friend Class Program
Shared Sub Main()
' path to the ZIP file and extraction directory
Dim zipPath As String = "archive.zip"
Dim extractPath As String = "extracted/"
' Extract all files in the ZIP archive to the specified directory
Using archive = New ZipArchive(zipPath)
archive.ExtractArchiveToDirectory(extractPath)
End Using
End Sub
End ClassImports IronZip
Friend Class Program
Shared Sub Main()
' path to the ZIP file and extraction directory
Dim zipPath As String = "archive.zip"
Dim extractPath As String = "extracted/"
' Extract all files in the ZIP archive to the specified directory
Using archive = New ZipArchive(zipPath)
archive.ExtractArchiveToDirectory(extractPath)
End Using
End Sub
End Class將文件新增至現有存檔
將 ZIP 檔案路徑傳遞給構造函數將打開 ZIP 檔案。使用相同的 AddArchiveEntry 方法將檔案添加到已打開的 ZIP 中,並使用 SaveAs 方法進行匯出。
using IronZip;
using System.IO;
class Program
{
static void Main()
{
// Open an existing ZIP file
using (var archive = new ZipArchive("archive.zip"))
{
// Add more files to the archive
archive.AddArchiveEntry("anotherfile.txt", File.ReadAllBytes("path/to/anotherfile.txt"));
// Save updates to the ZIP archive
archive.SaveAs("archive.zip");
}
}
}using IronZip;
using System.IO;
class Program
{
static void Main()
{
// Open an existing ZIP file
using (var archive = new ZipArchive("archive.zip"))
{
// Add more files to the archive
archive.AddArchiveEntry("anotherfile.txt", File.ReadAllBytes("path/to/anotherfile.txt"));
// Save updates to the ZIP archive
archive.SaveAs("archive.zip");
}
}
}Imports IronZip
Imports System.IO
Friend Class Program
Shared Sub Main()
' Open an existing ZIP file
Using archive = New ZipArchive("archive.zip")
' Add more files to the archive
archive.AddArchiveEntry("anotherfile.txt", File.ReadAllBytes("path/to/anotherfile.txt"))
' Save updates to the ZIP archive
archive.SaveAs("archive.zip")
End Using
End Sub
End ClassImports IronZip
Imports System.IO
Friend Class Program
Shared Sub Main()
' Open an existing ZIP file
Using archive = New ZipArchive("archive.zip")
' Add more files to the archive
archive.AddArchiveEntry("anotherfile.txt", File.ReadAllBytes("path/to/anotherfile.txt"))
' Save updates to the ZIP archive
archive.SaveAs("archive.zip")
End Using
End Sub
End Class提供許可和支援
IronZIP 是一個付費程式庫; 然而,免費試用授權也可以在這裡獲得。
如需了解更多有關 Iron Software 的資訊,請訪問我們的網站:https://ironsoftware.com/ 如需更多支援和諮詢,請詢問我們的團隊。
Iron Software 提供的支援
如需一般支援和技術詢問,請通過電子郵件與我們聯繫:support@ironsoftware.com
Curtis Chau 擁有卡爾頓大學計算機科學學士學位,專注於前端開發,擅長於 Node.js、TypeScript、JavaScript 和 React。Curtis 熱衷於創建直觀且美觀的用戶界面,喜歡使用現代框架並打造結構良好、視覺吸引人的手冊。