---
title: "List streams in a compound binary file in C#"
url: https://recursiveai.org/onearchive/cookbook/read-cfb-stream-directory/
description: "List a compound binary file’s streams and sizes in C#. Walk nested storages, see their paths, and tell stored names from archive display paths."
version: "1.2.0"
---

# List streams in a compound binary file in C#

**OneArchive** is a free, open-source archive and compression library for .NET from Recursive AI: zip, tar, 7z, RAR and more in RecursiveAI.OneArchive, with compression codecs 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/read-cfb-stream-directory/read-cfb-stream-directory.zip)

A compound file holds named byte streams in folder-like storages. List them from `notes.cfb` in the example ZIP.

```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.

```csharp
using RecursiveAI.OneArchive;
using RecursiveAI.OneArchive.Cfb;

using var file = File.OpenRead("notes.cfb");
using var cfb = new CompoundFileReader(file);
while (cfb.GetNextEntry() is { } entry)
    if (entry.Kind == ArchiveEntryKind.File)
        Console.WriteLine($"{entry.Name}: {entry.Size} bytes");
```

Paste the code above into Program.cs of a new `dotnet new console` project and `dotnet run`, or unzip [the example](https://recursiveai.org/onearchive/cookbook/read-cfb-stream-directory/read-cfb-stream-directory.zip) and `dotnet run`.

```text
Notes: 6 bytes
Attachments/Chart: 4 bytes
```

The listing prints each stream’s path and byte count without copying its contents. `Notes` contains `Draft` followed by a newline; `Attachments/Chart` contains `A,B` followed by a newline. Open an intact file with a seekable stream, such as `File.OpenRead`; a malformed directory or sector chain can raise `CompressionFormatException`.

## Variations

**Show storages as well as streams.** Remove the filter and print the entry kind:

```csharp
using RecursiveAI.OneArchive.Cfb;

using var file = File.OpenRead("notes.cfb");
using var cfb = new CompoundFileReader(file);
while (cfb.GetNextEntry() is { } entry)
    Console.WriteLine($"{entry.Kind}: {entry.Name}");
```

```text
File: Notes
Directory: Attachments
File: Attachments/Chart
```

## Related recipes

- [Read and write Microsoft compound files in C#](https://recursiveai.org/onearchive/cookbook/compound-files/)
- [Recover streams from a damaged compound file](https://recursiveai.org/onearchive/cookbook/recover-compound-file/)

---

## The short answer

Open a seekable input with `CompoundFileReader` and call `GetNextEntry()` until it returns `null`. Keep entries with `Kind == ArchiveEntryKind.File` to list streams; drop the filter to see storages too. Use `Name` for the path from the root and `Size` for the number of bytes in the stream. This reads the container directory, not the application data inside each stream.

## What is a compound file binary format stream?

A stream is a sequence of bytes with a name, like a file inside the container. A storage groups streams and other storages, like a folder. For example, in the supplied file `Attachments` is a storage; `Attachments/Chart` is a stream inside it. The reader presents them as `Directory` and `File` respectively. The root is available via `Root` and is not returned as a directory entry by `GetNextEntry()`.

Some older Office documents, Outlook `.msg` files, and `.msi` installers use this layout. Recognizing the container is not the same as interpreting the document, message, or installer: OneArchive exposes the streams and their bytes, not a parsed view of the application format. The [compound file docs](https://recursiveai.org/onearchive/docs/cfb/) describe the supported version 3 and 4 headers and directory structures. The CFB file signature is `D0 CF 11 E0 A1 B1 1A E1`; don’t assume a file is CFB just because its extension is `.doc` or `.msg`.

## How do I list streams inside nested CFB storages?

Use the same loop for every depth. The reader visits each storage before its children and joins the components with `/`, so there’s no recursive traversal to implement. To distinguish two streams with the same leaf name in different storages, keep the full `Name`, not just the last component. The order follows the directory tree’s name order; sort your results separately if your UI needs a different order.

`Name` is a display path with special characters escaped; `RawName` is the original name of the individual entry. For instance, a summary stream whose stored name begins with the control character U+0005 appears as `%0005SummaryInformation` in the listing. The percent escape is part of the reader’s path representation, not part of the stored name. When calling the reader’s `Find` or `OpenStream`, use stored names as described in the [name mapping docs](https://recursiveai.org/onearchive/docs/cfb/#listing-and-names), not the escaped display path.
