Create ZIP in C#

การนําเข้าสู่ ZIP Archives

Archives ZIP เป็นสิ่งสําคัญในการบีบอัดและรวมไฟล์หรือโฟลเดอร์หลายไฟล์ในภาชนะเดียว รูปแบบนี้ไม่เพียง แต่ลดขนาดไฟล์สําหรับการจัดเก็บและการส่ง แต่ยังรักษาข้อมูลโลหะการจัดการไฟล์ที่ง่ายขึ้น สารสํารองข้อมูล Zip ใช้กันอย่างแพร่หลายในแอปโต๊ะและเว็บสําหรับงานเช่นอัปโหลดดาวน์โหลดแชร์และรักษาความปลอดภัยไฟล์ผ่านการเข้ารหัส

ในบทความนี้เราจะดูวิธีการที่แตกต่างกันสําหรับการสร้างไฟล์ ZIP ใน C# ฯลฯ ฯลฯ ฯลฯ ฯลฯ ฯลฯ

C# ZIP ห้องสมุด

The Aspose.ZIP for .NET is a powerful API tailored for zipping and unzipping files and folders within .NET applications. It features AES encryption to secure your files within ZIP archives. You can easily install the API from ปริศนา or download the binaries from the ดาวน์โหลด section.

สร้างไฟล์ ZIP ใน C#

ในการบีบอัดไฟล์ไปยังไฟล์ ZIP โปรดทําตามขั้นตอนต่อไปนี้:

นี่คือตัวอย่างรหัสที่แสดงให้เห็นวิธีการเพิ่มไฟล์ไปยังไฟล์ ZIP โดยใช้ C#:

เพิ่มไฟล์หลายไฟล์ไปยังไฟล์ ZIP ใน C# {# เพิ่มไฟล์หลายไฟล์ไปยังไฟล์ ZIP}

เพื่อเพิ่มไฟล์หลายไฟล์ไปยังไฟล์ ZIP คุณสามารถเลือกจากวิธีการต่อไปนี้:

ใช้ FileStream

Utilize the ฟิล์ม class to zip files in C# by adding multiple files to the ZIP archive with the Archive.CreateEntry( String, FileStream) method. Here’s how:

การใช้ FileInfo

Alternatively, use the ฟิล์ม class to add files. This method loads the files using the ฟิล์ม class and adds them to the ZIP archive with the Archive.CreateEntry(หน้าแปลน, FileInfo) method. See the example below:

ใช้เส้นทางไฟล์

You can also add files directly by providing their paths to the Archive.CreateEntry(ชื่อ String, String path, Boolean openImmediately, ArchiveEntrySettings newEntrySettings) method. Here’s how:

เพิ่มโฟลเดอร์ไปยังเอกสาร ZIP ใน C# {#เพิ่มโฟลเดอร์ไปยังเอกสาร ZIP}

เพิ่มโฟลเดอร์ไปยังเอกสาร ZIP เป็นวิธีที่สะดวกในการรวมไฟล์หลายไฟล์ เพื่อสร้างไฟล์ Zip ใน C#** ทําตามขั้นตอนต่อไปนี้:

นี่คือตัวอย่างรหัสที่แสดงให้เห็นวิธีการเพิ่มโฟลเดอร์ไปยังไฟล์ ZIP ใน C#:

สร้างรหัสผ่านที่ปกป้อง ZIP ใช้ ZipCrypto ใน C# {# สร้างรหัสผ่านที่ปกป้อง ZIP-Archive-ใช้ ZipCrypto-ใน-CSharp}

To enhance security, you can create password-protected ZIP archives using ZipCrypto encryption. This is achieved by using the การตั้งค่า ArchiveEntrySettings class in the constructor of the อะคริฟต์, ซึ่งช่วยให้คุณระบุประเภทการเข้ารหัส

นี่คือตัวอย่างของวิธีการสร้างไฟล์ ZIP ที่ได้รับการป้องกันด้วยรหัสผ่านโดยใช้ ZipCrypto ใน C#:

สร้างรหัสผ่านที่ปกป้อง ZIP ด้วยการเข้ารหัส AES

Aspose.ZIP สําหรับห้องสมุด .NET ยังสนับสนุนการเข้ารหัส AES เพื่อรักษาความปลอดภัยของไฟล์ ZIP คุณสามารถเลือกจากวิธีการเข้ารหัส AES ต่อไปนี้:

  • AES128
  • AES192
  • AES256

To apply AES encryption, use the AesEcryptionตั้งค่า class. Here’s how to create a password-protected ZIP with AES encryption in C#:

โหมดการบีบอัดแบบสอดคล้อง

For cases involving multiple entries, configure the API for parallel compression using the คู่มือการเลือก class. Aspose.ZIP for .NET provides several parallel compression modes:

  • ไม่เคย - อย่าบีบอัดด้วยกัน
  • เสมอ - คอมเพรสเสมอใน parallel (ระมัดระวังเกี่ยวกับปัญหาภายนอกของหน่วยความจํา)
  • อัตโนมัติ - การตัดสินใจโดยอัตโนมัติว่าจะใช้การบีบอัดแบบด้ายขึ้นอยู่กับรายการ

นี่คือตัวอย่างที่แสดงให้เห็นว่าวิธีการตั้งค่าโหมดการบีบอัดแบบพารามิเตอร์ในขณะที่ zipping ไฟล์หลายไฟล์:

เรียนรู้เพิ่มเติมเกี่ยวกับ C# .NET ZIP Library

ลึกลงไปใน C# .NET ZIP API ของเราด้วยทรัพยากรต่อไปนี้:

ลอง ZIP Archives ออนไลน์

Explore our การสมัครออนไลน์ฟรี, ขึ้นอยู่กับ Aspose.ZIP สําหรับ .NET, เพื่อบีบอัดไฟล์ในไฟล์ ZIP ได้อย่างง่ายดาย

ข้อสรุป

In this article, you have learned how to programmatically create ZIP archives in C#. The provided code samples illustrate how to zip files in C#, add files and folders to ZIP archives, and create password-protected ZIP archives using both ZipCrypto and AES encryption methods. We also discussed parallel compression for efficiently handling large files. If you have any questions or need further assistance, feel free to reach out via our โพสต์.

ดูเพิ่มเติม

Unrar หรือ Extract ไฟล์โดยใช้ C#Unzip ไฟล์ใน ZIP Archives โดยใช้ C#สร้าง 7z (7-Zip) Archives ใน C# .NET
เปิดหรือสกัดไฟล์ 7z (7zip) ใน C# .NETสร้างและสกัด GZip Archives โดยใช้ C#แปลงไฟล์ RAR ไปยัง ZIP Archive ใน C#
แปลงไฟล์ ZIP ไปยัง TAR ใน C#สร้างไฟล์ ZIP Flat ใน C#สร้างเอกสารการประยุกต์ใช้ตนเองใน C#
สร้างไฟล์ TAR.GZ และ TAR.XZ ใน C#ลบไฟล์ในเอกสาร ZIP ใน C#สารสกัดจาก Nested ZIP ใน C#
เชื่อมต่อหลาย ZIP หรือ TAR Archives ใน C#วิธีการสร้างไฟล์ ZIPสารสกัด 7z ออนไลน์

More in this category