Create ZIP in C#

תגית: ZIP Archives

ארכיון 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 FileStream 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 FileInfo class to add files. This method loads the files using the FileInfo 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(כותרת, כותרת, כותרת פתוחה, ArchiveEntrySettings newEntrySettings) method. Here’s how:

הוסף קבצים לארכיון ZIP ב- C#

הוספת תיקיה לארכיון ZIP היא דרך נוחה לכלול קבצים מרובים. כדי ליצור קובץ Z IP ב- C#, בצע את השלבים הבאים:

הנה דגימה של קוד שמראה כיצד להוסיף תיקיה לארכיון ZIP ב- C#:

יצירת סיסמה מוגנת ZIP באמצעות ZipCrypto ב C#

To enhance security, you can create password-protected ZIP archives using ZipCrypto encryption. This is achieved by using the ArchiveEntryהגדרות class in the constructor of the ארכיון, אשר מאפשר לך לציין את סוג ההצפנה.

הנה דוגמה כיצד ליצור ארכיון ZIP מוגן סיסמה באמצעות ZipCrypto ב- C#:

יצירת סיסמה מוגנת ZIP עם הצפנה AES

הספרייה Aspose.ZIP עבור .NET תומכת גם בהצפנה AES כדי להגן על קבצי ZIP.

  • 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:

    • לעולם * - אל תדחפו במקביל.
  • תמיד - תמיד לחתוך במקביל (להיות זהיר בנוגע לבעיות מחוץ לזיכרון).
  • Auto - קובע באופן אוטומטי אם להשתמש בדחיסה מקבילה על בסיס הכרטיסים.

הנה דוגמה להוכיח כיצד להגדיר את מצב הדחיסה מקבילה בעת זיפוג קבצים מרובים:

למידע נוסף על C# .NET ZIP Library

נכנס עמוק יותר לתוך C# .NET ZIP API שלנו עם המשאבים הבאים:

בואו לנסות ZIP Archives Online

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 פורום.

ראה גם

להדביק או להוציא קבצים באמצעות C#Unzip קבצים בארכיון ZIP באמצעות C#יצירת 7z (7-Zip) ארכיון ב C# .NET
פתח או הוציא קובץ 7z (7zip) ב- C# .NETליצור ולהוציא ארכיון GZip באמצעות C#להמיר קבצים RAR ל- ZIP Archive ב- C#
להמיר ארכיון ZIP ל- TAR ב- C#יצירת ארכיון ZIP שטוח ב- C#יצירת ארכיון יישום עצמי ב- C#
יצירת קבצים TAR.GZ ו- TAR.XZ ב- C#למחוק קבצים בארכיון ZIP ב- C#חלץ ארכיונים מקוננים בפורמט ZIP ב-C#
שילוב ארכיון ZIP מרובים או TAR ב- C#כיצד ליצור קבצי ZIPתגית: 7Z Online

More in this category