View 7Z Archive Contents in C#
Aspose.ZIP for .NET lets a C# application open a 7Z archive and enumerate its stored entries without extracting every file. Use it to display file names and internal paths in archive browsers, upload inspectors, validation services, and other server-side workflows. The API works without installing 7-Zip, WinRAR, or another desktop archiver.
C# Example: List Files in a 7Z Archive
This short example opens a 7Z file and prints the name of every stored entry.
Open a 7Z Archive and List Its Entries
using Aspose.Zip.SevenZip;
using (var archive = new SevenZipArchive("input.7z"))
{
foreach (SevenZipArchiveEntry entry in archive.Entries)
{
Console.WriteLine(entry.Name);
}
}
How to Open a 7Z Archive Using C#
Add
Aspose.ZIP for .NET
to your project from
NuGet
. Create a
SevenZipArchive
from a file path or stream, then enumerate its Entries collection. Each
SevenZipArchiveEntry
exposes the stored name and available metadata. Reading the archive directory allows your application to inspect the package before deciding whether any entry should be extracted. See the
archive viewer overview
for the common workflow across supported formats.
Package Manager Console Command
PM> Install-Package Aspose.Zip
Steps to View Entries in a 7Z Archive
- Install and reference Aspose.ZIP for .NET.
- Pass the 7Z file path or stream to the
SevenZipArchiveconstructor. - Enumerate the archive’s
Entriescollection. - Read each
SevenZipArchiveEntry.Namevalue and any other required metadata. - Dispose the archive after inspection.
7Z Viewer Requirements
- A supported .NET runtime on Windows, Linux, or macOS
- A C# development environment such as Microsoft Visual Studio
- Aspose.ZIP for .NET referenced in the project
- Access to a valid, readable 7Z file or stream
What a 7Z Viewer Does — and Does Not Do
Viewing a 7Z archive means reading its entry directory and presenting information such as file names, internal paths, compressed and uncompressed sizes, modification times, and directory flags when those values are available. It does not extract every stored file automatically.
Aspose.ZIP handles the archive container; it does not visually render documents or media stored inside it. To preview a PDF, spreadsheet, image, or another stored file, extract or stream the selected entry and pass it to an appropriate renderer. When file content is required, continue with the archive extraction workflow .
Production and Security Guidance
Treat uploaded archives and their entry names as untrusted input. Limit archive size, entry count, memory consumption, and processing time; handle malformed, truncated, unsupported, and encrypted archives without exposing internal error details. Before extracting anything, normalize entry paths and reject absolute paths or parent-directory traversal. HTML-encode entry names before displaying them in a browser, extract only approved entries to an isolated destination, and dispose archive objects and streams deterministically.
If a 7Z archive encrypts its file names, provide the valid password when opening it. Aspose.ZIP reads protected archives but does not recover or bypass unknown passwords; see the password-protected archive guidance .
7Z Viewer FAQ
1. How do I list files inside a 7Z archive in C#?
Open the file with SevenZipArchive, enumerate its Entries collection, and read the Name property of each SevenZipArchiveEntry. Listing entries does not require extracting every stored file.
2. Can I view a 7Z archive without extracting it?
Yes. The SevenZipArchive constructor reads the archive structure and composes the entry list without decompressing each entry. Extract data only when the application needs the contents of a selected file.
3. Does Aspose.ZIP require 7-Zip or WinRAR to be installed?
No. Aspose.ZIP reads supported 7Z archives directly inside the .NET application and does not automate a desktop archiver.
4. Can I inspect a password-protected 7Z archive?
Yes, when the correct password is supplied. A password is required to list entries when the archive encrypts file names; Aspose.ZIP cannot recover an unknown password.
5. What metadata can I read from a 7Z entry?
SevenZipArchiveEntry exposes properties including Name, CompressedSize, UncompressedSize, ModificationTime, IsDirectory, and CompressionSettings. Availability and meaning can depend on the source archive.
Free App to Open 7Z Archives
Try the online 7Z viewer to inspect an archive without writing code.