---
title: "List RAR 5 files and extract a stored entry in C#"
url: https://recursiveai.org/onearchive/cookbook/list-rar5-and-extract-stored-entry/
description: "List a RAR 5 archive in C# and extract a stored file with OneArchive. Includes a sample; compressed and encrypted entries are not decoded."
version: "1.2.0"
---

# List RAR 5 files and extract a stored entry in C#

**OneArchive** is a free, open-source archive and compression library for .NET from Recursive AI: archives (zip, tar, 7z, RAR 5, cpio, ar, ISO) in RecursiveAI.OneArchive, codecs (zlib, gzip, xz, Zstandard, Brotli) in RecursiveAI.OneCompress. MIT or Apache-2.0, no native dependencies.

[NuGet](https://www.nuget.org/packages/RecursiveAI.OneArchive) · [GitHub](https://github.com/recursive-ai-oss/onearchive-csharp) · [Docs](https://recursiveai.org/onearchive/docs/) · [Download example (.zip)](https://recursiveai.org/onearchive/cookbook/list-rar5-and-extract-stored-entry/list-rar5-and-extract-stored-entry.zip)

List RAR 5 members and copy one stored (uncompressed) file. Compressed and encrypted data are not supported.

```shell
dotnet add package RecursiveAI.OneArchive
```

Requires [.NET 10](https://dotnet.microsoft.com/download/dotnet/10.0) (net10.0); .NET 9 and earlier aren’t supported.

`stored.rar` is in the example download; it contains a stored `hello.txt`.

```csharp
using RecursiveAI.OneArchive;
using RecursiveAI.OneArchive.Rar;

using var file = File.OpenRead("stored.rar");
using var reader = new RarReader(file);
while (reader.GetNextEntry() is { } entry)
{
    Console.WriteLine(entry.Name);
    if (entry.Name != "hello.txt") continue;
    using var data = reader.OpenEntryStream();
    using var output = File.Create("hello.txt");
    data.CopyTo(output);
}
```

```text
hello.txt
docs/sub/notes.txt
empty.txt
random.bin
ünï-cødé-文件-🙂.txt
link-to-hello
escaping-link
hard-to-hello
docs/sub
docs
empty-dir
```

Unzip [the example](https://recursiveai.org/onearchive/cookbook/list-rar5-and-extract-stored-entry/list-rar5-and-extract-stored-entry.zip), then `dotnet run`.

## The full program

`stored.rar` comes in the download from the public repository’s generated sample. Its `hello.txt` contains `Hello, RAR5 container!` plus a newline, repeated 40 times. The program lists all names but extracts only that file.

```csharp
using RecursiveAI.OneArchive;
using RecursiveAI.OneArchive.Rar;

using var file = File.OpenRead("stored.rar");
using var reader = new RarReader(file);
while (reader.GetNextEntry() is { } entry)
{
    Console.WriteLine(entry.Name);
    if (entry.Name != "hello.txt") continue;
    using var data = reader.OpenEntryStream();
    using var output = File.Create("hello.txt");
    data.CopyTo(output);
}
Console.WriteLine($"Extracted hello.txt: {new FileInfo("hello.txt").Length} bytes");
Console.WriteLine(File.ReadLines("hello.txt").First());
```

`dotnet run` prints:

```text
hello.txt
docs/sub/notes.txt
empty.txt
random.bin
ünï-cødé-文件-🙂.txt
link-to-hello
escaping-link
hard-to-hello
docs/sub
docs
empty-dir
Extracted hello.txt: 920 bytes
Hello, RAR5 container!
```

Opening compressed or encrypted entry data throws `RarUnsupportedException`; this is not a general RAR decompressor.

## Variations

Inspect the method of the selected entry without opening its data. Method 0 means stored.

```csharp
using RecursiveAI.OneArchive.Rar;

using var file = File.OpenRead("stored.rar");
using var reader = new RarReader(file);
while (reader.GetNextEntry() is RarEntry entry)
{
    if (entry.Name != "hello.txt") continue;
    Console.WriteLine(
        $"{entry.Name}: method {entry.Method}");
}
```

```text
hello.txt: method 0
```

## Related recipes

- [Create an ar archive in C#](https://recursiveai.org/onearchive/cookbook/create-ar-archive/)
- [Create a cpio archive in C#](https://recursiveai.org/onearchive/cookbook/create-cpio-archive/)
- [Compress and decompress Deflate64 in C#](https://recursiveai.org/onearchive/cookbook/compress-decompress-deflate64/)

## The short answer

Use `RarReader` to walk RAR 5 headers with `GetNextEntry`. It lists compressed entries as well as stored ones, but `OpenEntryStream` supports only unencrypted stored data. The example selects the known `hello.txt` member and copies it to a fixed local filename.

The download includes the input, so the program runs without a local archiving tool. The fixture is generated by the pinned public repository’s [sample generator](https://github.com/recursive-ai-oss/onearchive-csharp/blob/51053d161cb81164dd4380710afd9ebd8d0243c7/tools/rar-testdata/generate.sh). Its other members show names, directories and links; listing them does not extract them.

## How do I list RAR files in C#?

Open the archive as a stream and pass it to `RarReader`. Each `GetNextEntry` advances to the next member in file order. Read the member’s `Name`, `Kind` and `Size` for a basic inventory, or use `RarEntry` for RAR-specific fields. The variation above prints `Method` without opening any member content.

Listing and decoding are separate operations. According to the [RAR reader documentation](https://recursiveai.org/onearchive/docs/rar-reader/), compressed methods 1 through 5 can be listed fully; opening their data raises `RarUnsupportedException`. The exception identifies the member, method and dictionary size. Method 0 is the stored method, but encrypted stored data remains unsupported. Check `IsEncrypted` as well as the method when deciding whether your application can offer extraction.

A filename ending in `.rar` is not enough to decide compatibility. RAR 4 is detected and refused, and archives with encrypted headers are refused before their names can be listed. Those errors have distinct `RarUnsupportedKind` values, allowing an application to explain why an inventory is unavailable rather than reporting a successful empty archive.

## How do I extract files from a .RAR file?

For an unencrypted stored entry, call `OpenEntryStream` while that entry is current and copy it to the destination. Read to the end so that the default checksum verification runs. The full program does that for `hello.txt`, then prints its extracted size and first line.

The destination in this example is deliberately fixed. It never joins arbitrary archive member names onto an output directory. That distinction matters for a fixture that also contains link entries: an inventory is not an instruction to recreate every path or follow every link. For general directory extraction, use [`Archive.Extract`](https://recursiveai.org/onearchive/cookbook/safe-extraction/) rather than turning this selection loop into unchecked filesystem writes.

CRC-32 and, when present, BLAKE2sp are checked as stored content reaches its end. A mismatch raises `CompressionFormatException`. A copied destination may already contain bytes at that point; checksum verification is not a transactional promise that no output was written. If your application needs an all-or-nothing result, stage its output before publishing it.

Multipart archives need an explicit next-volume provider through `RarReaderOptions.Volumes`. The reader does not infer a complete volume set from the first filename. This page’s single-volume sample needs no provider. Neither supplying volumes nor selecting a stored entry adds support for RAR compression or encryption.
