Decompressing Multiple Files using Aspose.Zip for .NET

Introduction

Welcome to our comprehensive tutorial on decompressing multiple files using Aspose.Zip for .NET! If you’re looking to efficiently handle compressed files containing multiple entries, you’re in the right place. In this guide, we’ll walk you through the process step by step, using Aspose.Zip for .NET.

Prerequisites

Before we dive into the tutorial, make sure you have the following prerequisites in place:

  • Aspose.Zip for .NET: Ensure that you have the Aspose.Zip library for .NET installed. You can download it here.

  • Document Directory: Set up a directory where your documents are stored. You’ll use this as the base directory in the code.

Now, let’s get started with the step-by-step guide.

Import Namespaces

In your .NET project, begin by importing the necessary namespaces for Aspose.Zip:

using Aspose.Zip;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

Step 1: Compressing Multiple Files

To decompress multiple files, you first need a compressed file with multiple entries. Let’s create one:

string dataDir = "Your Document Directory";

// Run the compression method
CompressMultipleFiles.Run();

Step 2: Decompressing the Files

Now, let’s decompress the files step by step:

Step 2.1: Opening the Compressed File

using (FileStream zipFile = File.Open(dataDir + "CompressMultipleFiles_out.zip", FileMode.Open))
{
    // ...
}

Step 2.2: Listing Entries and Tracking Progress

StringBuilder sb = new StringBuilder("Entries are: ");
int percentReady = 0;

using (Archive archive = new Archive(zipFile, new ArchiveLoadOptions()
{
    EntryListed = (s, e) => { sb.AppendFormat("{0}, ", e.Entry.Name); },
    EntryExtractionProgressed = (s, e) =>
    {
        int percent = (int)((100 * e.ProceededBytes) / ((ArchiveEntry)s).UncompressedSize);
        if (percent > percentReady)
        {
            Console.WriteLine(string.Format("{0}% compressed", percent));
            percentReady = percent;
        }
    }
}))
{
    Console.WriteLine(sb.ToString(0, sb.Length - 2));

Step 2.3: Extracting the First Entry

using (var extracted = File.Create(dataDir + "alice_extracted_out.txt"))
{
    using (var decompressed = archive.Entries[0].Open())
    {
        // Read and write data from decompressed stream to the extracting file.
    }
}

Step 2.4: Extracting the Second Entry

archive.Entries[1].Extract(dataDir + "asyoulik_extracted_out.txt");

And there you have it! You’ve successfully decompressed multiple files using Aspose.Zip for .NET.

Conclusion

In this tutorial, we’ve covered the essential steps to decompress multiple files using Aspose.Zip for .NET. By following this guide, you can efficiently manage compressed files with ease.

FAQ’s

Q1: Can I use Aspose.Zip for .NET in both commercial and personal projects?

A1: Yes, Aspose.Zip for .NET can be used in both commercial and personal projects. For licensing details, refer to Aspose’s licensing information.

Q2: Is there a free trial available for Aspose.Zip for .NET?

A2: Yes, you can explore a free trial of Aspose.Zip for .NET here.

Q3: Where can I find additional support for Aspose.Zip for .NET?

A3: Visit the Aspose.Zip forum for community support and discussions.

Q4: How can I purchase a temporary license for Aspose.Zip for .NET?

A4: Obtain a temporary license for Aspose.Zip for .NET here.

Q5: Are there any specific system requirements for using Aspose.Zip for .NET?

A5: Refer to the documentation for detailed system requirements.