相关文章推荐
小百科
›
Zip or UnZip Files in .NET
博学的紫菜汤
7 月前
</noscript><div class="header"><div><a rel="nofollow" href="https://www.aspose.com" alt="Aspose Pty Ltd Logo" aria-label="Aspose Pty Ltd Logo" class="logo"/><div class="bar"><ul class="menu"><li class="products desktop-only"><a class="menu-item" rel="noopener nofollow" href="https://products.aspose.com">Products</a><ul class="submenu grid-4"><li><a class="menu-item" rel="noopener nofollow" href="https://products.aspose.com/total/"><span class="title">Aspose.Total</span><span class="description">Product Solution</span></a></li><li><a class="menu-item" rel="noopener nofollow" href="https://products.aspose.com/words/"><span class="title">Aspose.Words</span><span class="description">Product Solution</span></a></li><li><a class="menu-item" rel="noopener nofollow" href="https://products.aspose.com/pdf/"><span class="title">Aspose.PDF</span><span class="description">Product Solution</span></a></li><li><a class="menu-item" rel="noopener nofollow" href="https://products.aspose.com/cells/"><span class="title">Aspose.Cells</span><span class="description">Product Solution</span></a></li><li><a class="menu-item" rel="noopener nofollow" href="https://products.aspose.com/email/"><span class="title">Aspose.Email</span><span class="description">Product Solution</span></a></li><li><a class="menu-item" rel="noopener nofollow" href="https://products.aspose.com/slides/"><span class="title">Aspose.Slides</span><span class="description">Product Solution</span></a></li><li><a class="menu-item" rel="noopener nofollow" href="https://products.aspose.com/imaging/"><span class="title">Aspose.Imaging</span><span class="description">Product Solution</span></a></li><li><a class="menu-item" rel="noopener nofollow" href="https://products.aspose.com/barcode/"><span class="title">Aspose.BarCode</span><span class="description">Product Solution</span></a></li><li><a class="menu-item" rel="noopener nofollow" href="https://products.aspose.com/diagram/"><span class="title">Aspose.Diagram</span><span class="description">Product Solution</span></a></li><li><a class="menu-item" rel="noopener nofollow" href="https://products.aspose.com/tasks/"><span class="title">Aspose.Tasks</span><span class="description">Product Solution</span></a></li><li><a class="menu-item" rel="noopener nofollow" href="https://products.aspose.com/ocr/"><span class="title">Aspose.OCR</span><span class="description">Product Solution</span></a></li><li><a class="menu-item" rel="noopener nofollow" href="https://products.aspose.com/note/"><span class="title">Aspose.Note</span><span class="description">Product Solution</span></a></li><li><a class="menu-item" rel="noopener nofollow" href="https://products.aspose.com/cad/"><span class="title">Aspose.CAD</span><span class="description">Product Solution</span></a></li><li><a class="menu-item" rel="noopener nofollow" href="https://products.aspose.com/3d/"><span class="title">Aspose.3D</span><span class="description">Product Solution</span></a></li><li><a class="menu-item" rel="noopener nofollow" href="https://products.aspose.com/html/"><span class="title">Aspose.HTML</span><span class="description">Product Solution</span></a></li><li><a class="menu-item" rel="noopener nofollow" href="https://products.aspose.com/gis/"><span class="title">Aspose.GIS</span><span class="description">Product Solution</span></a></li><li><a class="menu-item" rel="noopener nofollow" href="https://products.aspose.com/zip/"><span class="title">Aspose.ZIP</span><span class="description">Product Solution</span></a></li><li><a class="menu-item" rel="noopener nofollow" href="https://products.aspose.com/page/"><span class="title">Aspose.Page</span><span class="description">Product Solution</span></a></li><li><a class="menu-item" rel="noopener nofollow" href="https://products.aspose.com/psd/"><span class="title">Aspose.PSD</span><span class="description">Product Solution</span></a></li><li><a class="menu-item" rel="noopener nofollow" href="https://products.aspose.com/omr/"><span class="title">Aspose.OMR</span><span class="description">Product Solution</span></a></li><li><a class="menu-item" rel="noopener nofollow" href="https://products.aspose.com/svg/"><span class="title">Aspose.SVG</span><span class="description">Product Solution</span></a></li><li><a class="menu-item" rel="noopener nofollow" href="https://products.aspose.com/finance/"><span class="title">Aspose.Finance</span><span class="description">Product Solution</span></a></li><li><a class="menu-item" rel="noopener nofollow" href="https://products.aspose.com/font/"><span class="title">Aspose.Font</span><span class="description">Product Solution</span></a></li><li><a class="menu-item" rel="noopener nofollow" href="https://products.aspose.com/tex/"><span class="title">Aspose.TeX</span><span class="description">Product Solution</span></a></li><li><a class="menu-item" rel="noopener nofollow" href="https://products.aspose.com/pub/"><span class="title">Aspose.PUB</span><span class="description">Product Solution</span></a></li><li><a class="menu-item" rel="noopener nofollow" href="https://products.aspose.com/drawing/"><span class="title">Aspose.Drawing</span><span class="description">Product Solution</span></a></li></ul></li><li class="desktop-only"><a class="menu-item" rel="noopener nofollow" href="#">Purchase</a><ul class="submenu"><li><a class="menu-item" rel="noopener nofollow" href="https://purchase.aspose.com/buy"><span class="title">Buy Now</span></a></li><li><a class="menu-item" rel="noopener nofollow" href="https://purchase.aspose.com/pricing"><span class="title">Pricing Information</span></a></li><li><a class="menu-item" rel="noopener nofollow" href="https://releases.aspose.com/"><span class="title">Free Trials</span></a></li><li><a class="menu-item" rel="noopener nofollow" href="https://purchase.aspose.com/temporary-license/"><span class="title">Temporary License</span></a></li><li><a class="menu-item" rel="noopener nofollow" href="https://purchase.aspose.com/policies/"><span class="title">Policies</span></a></li><li><a class="menu-item" rel="noopener nofollow" href="https://purchase.aspose.com/orders"><span class="title">My Orders & Quotes</span></a></li><li><a class="menu-item" rel="noopener nofollow" href="https://purchase.aspose.com/renew"><span class="title">Renew an Order</span></a></li><li><a class="menu-item" rel="noopener nofollow" href="https://purchase.aspose.com/upgrade"><span class="title">Upgrade an Order</span></a></li></ul></li><li class="desktop-only"><a class="menu-item" rel="noopener nofollow" href="#">Support</a><ul class="submenu"><li><a class="menu-item" rel="noopener nofollow" href="https://docs.aspose.com/"><span class="title">Docs</span></a></li><li><a class="menu-item" rel="noopener nofollow" href="https://reference.aspose.com/"><span class="title">API Reference</span></a></li><li><a class="menu-item" rel="noopener nofollow" href="https://demos.aspose.com/"><span class="title">Live Demos</span></a></li><li><a class="menu-item" rel="noopener nofollow" href="https://aspose.github.io/"><span class="title">Code Samples</span></a></li><li><a class="menu-item" rel="noopener nofollow" href="https://forum.aspose.com/"><span class="title">Free Support</span></a></li><li><a class="menu-item" rel="noopener nofollow" href="https://aspose-free-consulting.github.io/"><span class="title">Free Consulting</span></a></li><li><a class="menu-item" rel="noopener nofollow" href="https://helpdesk.aspose.com/"><span class="title">Paid Support</span></a></li><li><a class="menu-item" rel="noopener nofollow" href="https://consulting.aspose.com/"><span class="title">Paid Consulting</span></a></li><li><a class="menu-item" rel="noopener nofollow" href="https://blog.aspose.com/"><span class="title">Blog</span></a></li><li><a class="menu-item" rel="noopener nofollow" href="https://kb.aspose.com/"><span class="title">Knowledge Base</span></a></li><li><a class="menu-item" rel="noopener nofollow" href="https://releases.aspose.com/"><span class="title">New Releases</span></a></li><li><a class="menu-item" rel="noopener nofollow" href="https://status.aspose.com/"><span class="title">Status</span></a></li></ul></li><li class="desktop-only"><a class="menu-item" rel="noopener nofollow" href="https://websites.aspose.app/">Websites</a><ul class="submenu"><li><a class="menu-item" rel="noopener nofollow" href="https://websites.aspose.app/aspose/com/"><span class="title">aspose.com</span></a></li><li><a class="menu-item" rel="noopener nofollow" href="https://websites.aspose.app/aspose/cloud/"><span class="title">aspose.cloud</span></a></li><li><a class="menu-item" rel="noopener nofollow" href="https://websites.aspose.app/aspose/app/"><span class="title">aspose.app</span></a></li><li><a class="menu-item" rel="noopener nofollow" href="https://websites.aspose.app/groupdocs/com/"><span class="title">groupdocs.com</span></a></li><li><a class="menu-item" rel="noopener nofollow" href="https://websites.aspose.app/groupdocs/cloud/"><span class="title">groupdocs.cloud</span></a></li><li><a class="menu-item" rel="noopener nofollow" href="https://websites.aspose.app/groupdocs/app/"><span class="title">groupdocs.app</span></a></li><li><a class="menu-item" rel="noopener nofollow" href="https://websites.aspose.app/conholdate/com/"><span class="title">conholdate.com</span></a></li><li><a class="menu-item" rel="noopener nofollow" href="https://websites.aspose.app/conholdate/cloud/"><span class="title">conholdate.cloud</span></a></li><li><a class="menu-item" rel="noopener nofollow" href="https://websites.aspose.app/conholdate/app/"><span class="title">conholdate.app</span></a></li><li><a class="menu-item" rel="noopener nofollow" href="https://websites.aspose.app/containerize/com/"><span class="title">containerize.com</span></a></li><li><a class="menu-item" rel="noopener nofollow" href="https://websites.aspose.app/codeporting/com/"><span class="title">codeporting.com</span></a></li><li><a class="menu-item" rel="noopener nofollow" href="https://websites.aspose.app/fileformat/com/"><span class="title">fileformat.com</span></a></li></ul></li><li class="desktop-only"><a class="menu-item" rel="noopener nofollow" href="https://about.aspose.app">About</a><ul class="submenu"><li><a class="menu-item" rel="noopener nofollow" href="https://about.aspose.app"><span class="title">About Us</span></a></li><li><a class="menu-item" rel="noopener nofollow" href="https://about.aspose.app/contact/"><span class="title">Contact</span></a></li><li><a class="menu-item" rel="noopener nofollow" href="https://about.aspose.app/legal/"><span class="title">Legal</span></a></li><li><a class="menu-item" rel="noopener nofollow" href="https://about.aspose.app/affiliates/"><span class="title">Affiliates</span></a></li><li><a class="menu-item" rel="noopener nofollow" href="https://about.aspose.app/events/"><span class="title">Events</span></a></li><li><a class="menu-item" rel="noopener nofollow" href="https://about.aspose.app/acquisition/"><span class="title">Acquisition</span></a></li></ul></li><li class="language"><span class="menu-item"><svg viewbox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" fill="currentcolor"><path d="M12 4c4.4183.0 8 3.58172 8 8 0 4.4183-3.5817 8-8 8-4.41828.0-8-3.5817-8-8 0-4.41828 3.58172-8 8-8zm-.381 11.428L8.57155 15.4289C8.9774 16.7012 9.60471 17.924 10.4358 19.0678 10.8198 19.1532 11.2151 19.2073 11.6191 19.2282L11.619 15.428zM15.4284 15.4289 12.38 15.428 12.3809 19.2282C12.7849 19.2073 13.1802 19.1532 13.5641 19.0687 14.3953 17.924 15.0226 16.7012 15.4284 15.4289zM18.3762 15.4285 16.0984 15.4284C15.7811 16.5746 15.31 17.6754 14.703 18.7169c1.5738-.634 2.8744-1.806 3.6732-3.2884zM7.90159 15.4284 5.62381 15.4285c.79877 1.4824 2.09943 2.6544 3.67446 3.2885-.60825-1.0416-1.07936-2.1424-1.39668-3.2886zM7.4355 12.3803 4.77175 12.3809C4.81342 13.1846 4.98617 13.9535 5.26904 14.6669L7.71488 14.6666c-.15933-.7461-.25402-1.5094-.27938-2.2863zM15.9653 12.3808 12.38 12.38v2.286L15.6434 14.6671c.1843-.7493.2928-1.5134.321899999999999-2.2863zM19.2282 12.3809 16.5645 12.3803C16.5391 13.1572 16.4444 13.9205 16.2851 14.6666L18.731 14.6669C19.0138 13.9535 19.1866 13.1846 19.2282 12.3809zM11.619 12.38 8.03469 12.3808C8.06384 13.1537 8.17229 13.9178 8.35656 14.6671L11.619 14.666V12.38zM7.78068 8.95226 5.43294 8.95224C5.05284 9.76985 4.82095 10.6703 4.77175 11.6191L7.4329 11.6194C7.45634 10.71 7.57476 9.81899 7.78068 8.95226zM15.5678 8.95239 12.38 8.952v2.667h3.588L15.9673 11.5875C15.9382 10.6945 15.8033 9.81313 15.5678 8.95239zM18.5671 8.95224 16.2193 8.95226C16.4252 9.81899 16.5437 10.71 16.5671 11.6194L19.2282 11.6191C19.1791 10.6703 18.9472 9.76985 18.5671 8.95224zM11.619 8.952 8.43217 8.95239C8.16446 9.93108 8.02667 10.9364 8.02667 11.9553L8.031 11.619h3.588V8.952zM9.22964 5.31048 9.02453 5.39982c-1.31708.59469-2.4243 1.57203-3.17995 2.79029L7.98594 8.19044C8.28727 7.19147 8.70587 6.2283 9.22964 5.31048zm3.15126-.53873L12.38 8.19 15.3312 8.18991c-.3925-1.12859-.9602-2.21592-1.6906-3.24091C13.2322 4.85405 12.8116 4.79408 12.3809 4.77175zm2.3884.53883L14.9321 5.60148C15.3809 6.43124 15.7444 7.2965 16.0141 8.19044L18.1554 8.19011C17.3607 6.9088 16.177 5.89399 14.7693 5.31058zm-4.1992-.40747L10.3594 4.949C9.629 5.97399 9.06128 7.06132 8.66884 8.18991L11.619 8.19 11.6191 4.77175C11.262 4.79027 10.9117 4.83467 10.5701 4.90311z"/></svg><span>English</span></span><ul class="submenu grid-3"/></li></ul></div></div></div><div class="main_block"><div class="leftbar"><div class="collapse_leftbar_btn"><svg xmlns="http://www.w3.org/2000/svg" viewbox="0 0 320 512"><path d="M310.6 233.4c12.5 12.5 12.5 32.8.0 45.3l-192 192c-12.5 12.5-32.8 12.5-45.3.0s-12.5-32.8.0-45.3L242.7 256 73.4 86.6c-12.5-12.5-12.5-32.8.0-45.3s32.8-12.5 45.3.0l192 192z"/></svg></div><nav><div class="td-sidebar__search d-flex align-items-center"><input type="text" id="internalSearch" class="search_input" placeholder="Search " aria-label="" autocomplete="off" data-index="docs.aspose.com"/> <button class="btn btn-link td-sidebar__toggle d-md-none p-0 ml-3 fa fa-bars" type="button" data-toggle="collapse" data-target="#td-section-nav" aria-controls="td-docs-nav" aria-expanded="false" aria-label="Toggle section navigation"/></div><ul><li class="active open"><a href="/zip/net/">Aspose.ZIP for .NET</a></li><li class="no-indent"><ul><li class="closeli"><a href="/zip/net/getting-started/">Getting Started</a></li><li class="active open"><a href="/zip/net/developer-guide/">Developer Guide</a></li><li class="no-indent"><ul><li><a href="/zip/net/introduction/">Introduction</a></li><li class="active open"><a href="/zip/net/popular-archive-formats/">Most common archives</a></li><li class="no-indent"><ul><li><a href="/zip/net/how-to/">How To</a></li><li class="active"><a href="/zip/net/compressing-and-decompressing-files/">ZIP/UnZIP Files</a></li><li class="no-indent"><ul/></li><li><a href="/zip/net/compressing-and-decompressing-folders/">ZIP/UnZIP Folders</a></li><li><a href="/zip/net/flatten-nested-zip/">Make a ZIP archive flat</a></li><li><a href="/zip/net/working-with-7z-archives/">Working with 7z Archives</a></li><li><a href="/zip/net/extracting-rar-archives/">Extracting RAR Archives</a></li></ul></li><li class="closeli"><a href="/zip/net/password-protection/">Encryption and decryption</a></li><li class="closeli"><a href="/zip/net/multi-volume-archives/">Multi-volume archives</a></li><li class="closeli"><a href="/zip/net/using-for-asp.net-web-app/">Using for ASP.NET web applications</a></li><li class="closeli"><a href="/zip/net/archives-for-unix-like-systems/">Typical archives for Unix-like platform</a></li><li class="closeli"><a href="/zip/net/archives-for-windows-platform/">Distinctive archives for Windows</a></li><li class="closeli"><a href="/zip/net/report-progress-and-cancel/">Archive events</a></li><li class="closeli"><a href="/zip/net/archive-conversion/">Archive conversion</a></li><li class="closeli"><a href="/zip/net/parallel/">Parallel compression</a></li><li class="closeli"><a href="/zip/net/archive-merge/">Archive merging</a></li><li><a href="/zip/net/retrieve-images-from-docx/">Retrieve images from *.docx Word document</a></li></ul></li><li><a href="/zip/net/api-reference/">API Reference</a></li></ul></li></ul></nav></div><div class="docs_information"><div class="breadcrumb_block"><ul><li><a href="/" aria-label="Go to home page"><i class="fa fa-house"/></a></li><li><a href="/zip/">Aspose.Zip</a></li><li><a href="/zip/net/">.NET</a></li><li><a href="/zip/net/developer-guide/">Developer Guide</a></li><li><a href="/zip/net/popular-archive-formats/">Most common archives</a></li><li><a href="/zip/net/compressing-and-decompressing-files/">ZIP/UnZIP Files</a></li></ul></div><h1>Zip or UnZip Files in .NET</h1><div data-nosnippet="" id="toc-right-side-bar" class="anchors_block"><div class="anchors_block_top"><div>Contents</div>[ ]</div><div class="section_nav_list" id="collapseToC"><nav id="TableOfContents"><ul><li><a href="/zip/net/compressing-and-decompressing-files/#overview">Overview</a></li><li><a href="/zip/net/compressing-and-decompressing-files/#zip-or-compress-files-in-c-and-decompress-or-unzip-files-in-c">Zip or Compress files in C# and Decompress or Unzip files in C#</a></li><li><a href="/zip/net/compressing-and-decompressing-files/#compressing-files"><strong>Compressing Files</strong></a><ul><li><a href="/zip/net/compressing-and-decompressing-files/#compressing-single-file"><strong>Compressing Single File</strong></a></li><li><a href="/zip/net/compressing-and-decompressing-files/#compressing-multiple-files"><strong>Compressing Multiple Files</strong></a></li><li><a href="/zip/net/compressing-and-decompressing-files/#compress-files-by-file-info"><strong>Compress Files by File Info</strong></a></li><li><a href="/zip/net/compressing-and-decompressing-files/#storing-files-to-archives-without-compression"><strong>Storing Files to Archives without Compression</strong></a></li><li><a href="/zip/net/compressing-and-decompressing-files/#using-parallelism-to-compress-files"><strong>Using Parallelism to Compress Files</strong></a></li><li><a href="/zip/net/compressing-and-decompressing-files/#lzma-compression-within-zip-archive"><strong>LZMA Compression within ZIP Archive</strong></a></li><li><a href="/zip/net/compressing-and-decompressing-files/#bzip2-compression-within-zip-archive"><strong>BZip2 Compression within ZIP Archive</strong></a></li><li><a href="/zip/net/compressing-and-decompressing-files/#ppmd-compression-within-zip-archive"><strong>PPMd Compression within ZIP Archive</strong></a></li></ul></li><li><a href="/zip/net/compressing-and-decompressing-files/#decompressing-archives"><strong>Decompressing Archives</strong></a><ul><li><a href="/zip/net/compressing-and-decompressing-files/#decompress-archive-having-single-file"><strong>Decompress Archive having Single File</strong></a></li><li><a href="/zip/net/compressing-and-decompressing-files/#decompress-archive-having-multiple-files"><strong>Decompress Archive having Multiple Files</strong></a></li><li><a href="/zip/net/compressing-and-decompressing-files/#extract-stored-archive-without-compression"><strong>Extract Stored Archive without Compression</strong></a></li></ul></li></ul></nav></div></div><h2 id="overview">Overview</h2><p>This article will teach you how to programmatically compress Zip files using a variety of methods utilising C# or the.NET API and sample code. You will learn how to zip or compress one or more files, as well as how to zip files simultaneously. You will also learn how to decompress or unzip files as well.</p><h2 id="zip-or-compress-files-in-c-and-decompress-or-unzip-files-in-c">Zip or Compress files in C# and Decompress or Unzip files in C#</h2><p>Aspose.ZIP API lets you compress and decompress files without worrying about the underlying file structure. This article shows working with single as well as multiple file compression.</p><h2 id="compressing-files"><strong>Compressing Files</strong></h2><h3 id="compressing-single-file"><strong>Compressing Single File</strong></h3><p><a id="csharp-compressing-single-file"><strong><em>Steps:</em> Compressing Single File in C#</strong></a></p><ol><li>Create a <a href="https://learn.microsoft.com/en-us/dotnet/api/system.io.filestream?view=net-7.0" target="_blank" rel="nofollow">file stream</a> with the desired name of your output zip file.</li><li>Create file stream of the data file to be compressed.</li><li>Create an instance of <a href="https://reference.aspose.com/zip/net/aspose.zip/archive/" target="_blank" rel="nofollow">Archive</a> class and pass it instance of <a href="https://reference.aspose.com/zip/net/aspose.zip.saving/archiveentrysettings/" target="_blank" rel="nofollow">ArchiveEntrySettings</a> class.</li><li>Add data file created in step 2 using <a href="https://reference.aspose.com/zip/net/aspose.zip/archive/createentry/" target="_blank" rel="nofollow">Archive.CreateEntry</a> method.</li><li>Zip the data file using <a href="https://reference.aspose.com/zip/net/aspose.zip/archive/save/" target="_blank" rel="nofollow">Archive.Save</a> method and pass it the file stream created in step 1.</li></ol><h3 id="compressing-multiple-files"><strong>Compressing Multiple Files</strong></h3><p><a id="csharp-compressing-multiple-files"><strong><em>Steps:</em> Compressing Multiple Files in C#</strong></a></p><ol><li>Create a file stream with the desired name of your output zip file.</li><li>Create file stream of the first data file to be compressed.</li><li>Create file stream of the second data file to be compressed.</li><li>Create an instance of <a href="https://reference.aspose.com/zip/net/aspose.zip/archive/" target="_blank" rel="nofollow">Archive</a> class.</li><li>Add data files created in step 2 and step 3 using <a href="https://reference.aspose.com/zip/net/aspose.zip/archive/createentry/" target="_blank" rel="nofollow">Archive.CreateEntry</a> method.</li><li>Create an instance of <a href="https://reference.aspose.com/zip/net/aspose.zip.saving/archivesaveoptions/" target="_blank" rel="nofollow">ArchiveSaveOptions</a> class.</li><li>Zip the data files using <a href="https://reference.aspose.com/zip/net/aspose.zip/archive/save/" target="_blank" rel="nofollow">Archive.Save</a> method and pass it the file stream created in step 1 and instance of <strong>ArchiveSaveOptions</strong> created in above step.</li></ol><h3 id="compress-files-by-file-info"><strong>Compress Files by File Info</strong></h3><p><a id="csharp-compress-files-by-file-info"><strong><em>Steps:</em> Compress Files by File Info in C#</strong></a></p><ol><li>Open a file stream with <strong>FileMode.Create</strong> with the desired name of your output zip file.</li><li>Create <a href="https://learn.microsoft.com/en-us/dotnet/api/system.io.fileinfo?view=net-7.0" target="_blank" rel="nofollow">FileInfo</a> object of your first data file to be compressed.</li><li>Create <strong>FileInfo</strong> object of your second data file to be compressed.</li><li>Create an instance of <a href="https://reference.aspose.com/zip/net/aspose.zip/archive/" target="_blank" rel="nofollow">Archive</a> class.</li><li>Add data files created in step 2 and step 3 using <a href="https://reference.aspose.com/zip/net/aspose.zip/archive/createentry/" target="_blank" rel="nofollow">Archive.CreateEntry</a> method.</li><li>Create an instance of <a href="https://reference.aspose.com/zip/net/aspose.zip.saving/archivesaveoptions/" target="_blank" rel="nofollow">ArchiveSaveOptions</a> class.</li><li>Zip the data files using <a href="https://reference.aspose.com/zip/net/aspose.zip/archive/save/" target="_blank" rel="nofollow">Archive.Save</a> method and pass it the file stream created in step 1 and instance of <strong>ArchiveSaveOptions</strong> created in above step.</li></ol><h3 id="storing-files-to-archives-without-compression"><strong>Storing Files to Archives without Compression</strong></h3><p><a id="csharp-storing-files-to-archives-without-compression"><strong><em>Steps:</em> Storing Files to Archives without Compression using C#</strong></a></p><ol><li>Open a file stream with <strong>FileMode.Create</strong> with the desired name of your output zip file.</li><li>Create <a href="https://learn.microsoft.com/en-us/dotnet/api/system.io.fileinfo?view=net-7.0" target="_blank" rel="nofollow">FileInfo</a> objects for your data files to be stored in archive.</li><li>Create an instance of <a href="https://reference.aspose.com/zip/net/aspose.zip.saving/archiveentrysettings/" target="_blank" rel="nofollow">ArchiveEntrySettings</a> class and pass it instance of <a href="https://reference.aspose.com/zip/net/aspose.zip.saving/storecompressionsettings/" target="_blank" rel="nofollow">StoreCompressionSettings</a> class.</li><li>Create an instance of <a href="https://reference.aspose.com/zip/net/aspose.zip/archive/" target="_blank" rel="nofollow">Archive</a> class and pass it instance of <strong>ArchiveEntrySettings</strong> class created in above step.</li><li>Add <strong>FileInfo</strong> objects created in step 2 using <a href="https://reference.aspose.com/zip/net/aspose.zip/archive/createentry/" target="_blank" rel="nofollow">Archive.CreateEntry</a> method.</li><li>Create instance of <a href="https://reference.aspose.com/zip/net/aspose.zip.saving/archivesaveoptions/" target="_blank" rel="nofollow">ArchiveSaveOptions</a> and set <strong>Encoding = Encoding.ASCII</strong>.</li><li>Zip the data files using <a href="https://reference.aspose.com/zip/net/aspose.zip/archive/save/" target="_blank" rel="nofollow">Archive.Save</a> method and pass it the file stream created in step 1 and instance of <strong>ArchiveSaveOptions</strong> created in above step.</li></ol><h3 id="using-parallelism-to-compress-files"><strong>Using Parallelism to Compress Files</strong></h3><p><a id="csharp-using-parallelism-to-compress-files"><strong><em>Steps:</em> Using Parallelism to Compress Files using C#</strong></a></p><ol><li>Open a file stream with <strong>FileMode.Create</strong> with the desired name of your output zip file.</li><li>Open file streams with <strong>FileMode.Open</strong> and <strong>FileAccess.Read</strong> for your first and second data files to be compressed.</li><li>Create an instance of <a href="https://reference.aspose.com/zip/net/aspose.zip/archive/" target="_blank" rel="nofollow">Archive</a> class.</li><li>Add data files created in step 2 using <a href="https://reference.aspose.com/zip/net/aspose.zip/archive/createentry/" target="_blank" rel="nofollow">Archive.CreateEntry</a> method.</li><li>Create an instance of <a href="https://reference.aspose.com/zip/net/aspose.zip.saving/paralleloptions/" target="_blank" rel="nofollow">ParallelOptions</a> and set <strong>ParallelCompressInMemory = ParallelCompressionMode.Always</strong>.</li><li>Create an instance of <a href="https://reference.aspose.com/zip/net/aspose.zip.saving/archivesaveoptions/" target="_blank" rel="nofollow">ArchiveSaveOptions</a> and set its property <strong>ParallelOptions</strong> with the above instance.</li><li>Zip the data files using <a href="https://reference.aspose.com/zip/net/aspose.zip/archive/save/" target="_blank" rel="nofollow">Archive.Save</a> method and pass it the file stream created in step 1 and instance of <strong>ArchiveSaveOptions</strong> created in above step.</li></ol><h3 id="lzma-compression-within-zip-archive"><strong>LZMA Compression within ZIP Archive</strong></h3><p>The <strong>Lempel–Ziv–Markov chain algorithm</strong> (<strong>LZMA</strong>) is an algorithm used to perform lossless data compression. LZMA uses a dictionary compression algorithm, the compressed stream is a stream of bits. LZMA compression within the ZIP archive allows ZIP containers to contain LZMA compressed entries. The following code example shows the implementation of LZMA compression using Aspose.ZIP API.</p><p><a id="csharp-lzma-compression-within-zip-archive"><strong><em>Steps:</em> LZMA Compression within ZIP Archive using C#</strong></a></p><ol><li>Open a file stream with <strong>FileMode.Create</strong> with the desired name of your output zip file.</li><li>Create an instance of <a href="https://reference.aspose.com/zip/net/aspose.zip.saving/archiveentrysettings/" target="_blank" rel="nofollow">ArchiveEntrySettings</a> and pass it the instance of <a href="https://reference.aspose.com/zip/net/aspose.zip.saving/lzmacompressionsettings/" target="_blank" rel="nofollow">LzmaCompressionSettings</a> class.</li><li>Create an instance of <a href="https://reference.aspose.com/zip/net/aspose.zip/archive/" target="_blank" rel="nofollow">Archive</a> class and pass it the instance of <strong>ArchiveEntrySettings</strong> created above.</li><li>Add data files to be compressed via file paths using <a href="https://reference.aspose.com/zip/net/aspose.zip/archive/createentry/" target="_blank" rel="nofollow">Archive.CreateEntry</a> method.</li><li>Zip the data files using <a href="https://reference.aspose.com/zip/net/aspose.zip/archive/save/" target="_blank" rel="nofollow">Archive.Save</a> method.</li></ol><h3 id="bzip2-compression-within-zip-archive"><strong>BZip2 Compression within ZIP Archive</strong></h3><p>BZip2 compression settings allow ZIP container to contain BZip2 compressed entries. The following code example shows the implementation of BZip2 compression using Aspose.ZIP API.</p><p><a id="csharp-bzip2-compression-within-zip-archive"><strong><em>Steps:</em> BZip2 Compression within ZIP Archive using C#</strong></a></p><ol><li>Open a file stream with <strong>FileMode.Create</strong> with the desired name of your output zip file.</li><li>Create an instance of <a href="https://reference.aspose.com/zip/net/aspose.zip.saving/archiveentrysettings/" target="_blank" rel="nofollow">ArchiveEntrySettings</a> and pass it the instance of <a href="https://reference.aspose.com/zip/net/aspose.zip.saving/bzip2compressionsettings/" target="_blank" rel="nofollow">Bzip2CompressionSettings</a> class.</li><li>Create an instance of <a href="https://reference.aspose.com/zip/net/aspose.zip/archive/" target="_blank" rel="nofollow">Archive</a> class and pass it the instance of <strong>ArchiveEntrySettings</strong> created above.</li><li>Add data files to be compressed via file paths using <a href="https://reference.aspose.com/zip/net/aspose.zip/archive/createentry/" target="_blank" rel="nofollow">Archive.CreateEntry</a> method.</li><li>Zip the data files using <a href="https://reference.aspose.com/zip/net/aspose.zip/archive/save/" target="_blank" rel="nofollow">Archive.Save</a> method.</li></ol><h3 id="ppmd-compression-within-zip-archive"><strong>PPMd Compression within ZIP Archive</strong></h3><p>PPMd compression settings allow ZIP container to contain PPMd compressed entries. The following code example demonstrated the implementation of PPMd compression using Aspose.ZIP API.</p><p><a id="csharp-ppmd-compression-within-zip-archive"><strong><em>Steps:</em> PPMd Compression within ZIP Archive using C#</strong></a></p><ol><li>Open a file stream with <strong>FileMode.Create</strong> with the desired name of your output zip file.</li><li>Create an instance of <a href="https://reference.aspose.com/zip/net/aspose.zip.saving/archiveentrysettings/" target="_blank" rel="nofollow">ArchiveEntrySettings</a> and pass it the instance of <a href="https://reference.aspose.com/zip/net/aspose.zip.saving/ppmdcompressionsettings/" target="_blank" rel="nofollow">PPMdCompressionSettings</a> class.</li><li>Create an instance of <a href="https://reference.aspose.com/zip/net/aspose.zip/archive/" target="_blank" rel="nofollow">Archive</a> class and pass it the instance of <strong>ArchiveEntrySettings</strong> created above.</li><li>Add data files to be compressed via file paths using <a href="https://reference.aspose.com/zip/net/aspose.zip/archive/createentry/" target="_blank" rel="nofollow">Archive.CreateEntry</a> method.</li><li>Zip the data files using
推荐文章