View Archive Contents in C#
List files and inspect entry metadata in ZIP, 7Z, RAR, TAR, CPIO, and XAR archives with .NET.
Archive Viewer API for .NET
Aspose.ZIP for .NET lets C# applications open an archive and enumerate its entries without first extracting every contained file. Developers can build archive browsers, upload inspectors, content inventories, validation services, and preview workflows that display file names, paths, sizes, and other format-specific metadata.
The API runs inside .NET applications and does not require WinRAR, 7-Zip, or another desktop archiver. Use this overview to understand the common viewing workflow, then select a format-specific guide for the archive container your application receives.
What Does Viewing an Archive Mean?
Viewing an archive means reading its directory of entries and presenting information about the files and folders stored inside. Depending on the format, an entry can expose a name, internal path, original size, compressed size, modification time, or other metadata. This operation is also described as list archive contents in C#, inspect archive entries in .NET, read a ZIP file list, or browse an archive programmatically.
Archive viewing does not automatically render the documents, images, or media stored in the container. If an application needs a visual preview of an entry, it must extract or stream that entry and pass it to a suitable document or media renderer.
When to Use an Archive Viewer
Use archive viewing when an application must inspect a package before deciding what to extract. Common scenarios include file-upload portals, document intake systems, backup catalogs, compliance inventories, migration tools, digital asset pipelines, and support utilities. Listing entries first can help an application show users what an archive contains, locate a required file, enforce naming rules, or estimate processing work.
If the goal is to restore files to disk, use the archive extraction overview . If the goal is to open an encrypted container, use the password-protected archive guide .
How to View Archive Entries in C#
A typical archive-viewing workflow has five steps:
- Receive the archive: Open a local file or application-managed stream.
- Identify the container: Select the API class that matches the actual archive format.
- Open the archive: Construct the format-specific archive object without extracting all entries.
- Enumerate entries: Read the entries collection and the metadata exposed by each entry.
- Present or validate results: Display a safe file listing or apply application rules before optional extraction.
Use the container type rather than the filename extension alone when processing untrusted uploads. Each archive family has its own class and may expose different entry properties.
Supported Archive Viewer Formats
The format-specific viewer guides cover these common archive containers:
- ZIP viewer
: Open a
.zipfile withArchiveand enumerateEntries. - 7Z viewer
: Open a
.7zfile withSevenZipArchiveand inspect its entries. - RAR viewer
: Open a
.rarfile withRarArchiveand list stored items. - TAR viewer
: Read a
.tarcontainer withTarArchiveand enumerate its entries. - CPIO viewer
: Inspect a
.cpioarchive throughCpioArchive. - XAR viewer
: Browse entries in an
.xarpackage withXarArchive.
The exact metadata available can vary by format. Consult the API reference for the entry type used by the selected archive class.
C# Example: List Files in a ZIP Archive
The following example opens a ZIP archive and writes each entry name to the console. It reads the archive directory and does not extract the entries:
using Aspose.Zip;
using (var archive = new Archive("input.zip"))
{
foreach (ArchiveEntry entry in archive.Entries)
{
Console.WriteLine(entry.Name);
}
}
For 7Z, RAR, TAR, CPIO, or XAR, use the corresponding archive class shown in the format-specific guide. Do not assume that every entry type exposes an identical set of properties.
Install Aspose.ZIP for .NET
Add the Aspose.ZIP NuGet package to a C# project, then import the namespace required by the target archive format. Aspose.ZIP can be used in supported .NET environments on Windows, Linux, and macOS.
Package Manager Console
PM> Install-Package Aspose.Zip
Production Guidance for Archive Inspection
Treat archive metadata and entry names as untrusted input. Merely listing an archive is safer than extracting all of it, but parsing still consumes memory, CPU time, and input streams. For production workflows:
- Set limits: Restrict input size, entry count, nesting, processing time, and memory usage.
- Validate paths: Normalize entry names and reject absolute paths or parent-directory traversal before extraction.
- Handle failures: Catch malformed archives, unsupported features, encrypted input, truncated streams, and I/O errors.
- Encode output: HTML-encode entry names before showing them in a web interface.
- Avoid automatic extraction: Extract only approved entries to an isolated destination.
- Dispose resources: Close archive objects and streams deterministically after inspection.
Archive Viewing vs. Extraction
An archive viewer reads the container index so an application can list and inspect entries. Extraction decompresses entry data and writes or streams the original files. Use viewing for discovery, selection, and validation; use extraction only when the application needs the actual contents of one or more entries.
Aspose.ZIP provides the archive layer. Rendering an extracted PDF, Word document, spreadsheet, image, audio file, or video requires a viewer appropriate to that file type.
Related Archive Workflows
Archive inspection often comes before selective extraction, conversion, or validation. Explore extracting archives in C# , converting archive formats , and unlocking password-protected archives . For direct implementation details, choose the viewer guide for ZIP , 7Z , RAR , TAR , CPIO , or XAR .
Aspose.ZIP for .NET Resources
- Explore Aspose.ZIP for .NET
- Read the developer documentation
- Browse the .NET API reference
- Review C# examples on GitHub
- Install Aspose.ZIP from NuGet
Archive Viewer FAQ
1. How do I view the contents of an archive in C#?
Open the archive with the Aspose.ZIP class for its format, enumerate the Entries collection, and read the entry names and available metadata. You do not need to extract every entry to create a file listing.
2. Which archive formats can I inspect with these .NET viewer guides?
The viewer section provides format-specific guidance for ZIP, 7Z, RAR, TAR, CPIO, and XAR archives. Use the class that matches the actual container format.
3. Does Aspose.ZIP render files stored inside an archive?
No. Aspose.ZIP lists and extracts archive entries. To visually render a stored document or media file, stream or extract that entry and use a viewer designed for its file type.
4. Do I need 7-Zip or WinRAR installed?
No. Aspose.ZIP for .NET reads supported archive formats inside the application without automating desktop archive software.
5. Can I inspect a password-protected archive?
A protected archive requires a valid password and the format-specific load options before its entries can be accessed. Aspose.ZIP does not recover or bypass unknown passwords.