Table of Contents

PstFile Class

Definition

Namespace
Bodu.IO.Pst
Assembly
Bodu.IO.Pst.dll
Package
Bodu.IO.Pst 0.7.1
Source
PstFile.cs

Provides a disposable, read-only session over a PST file's node database (Unicode or ANSI format): the header facts, the node directory, and per-node data and subnode access.

public sealed class PstFile : IDisposable
Inheritance
PstFile
Implements
Inherited Members
Extension Methods

Remarks

This is the container layer of MS-PST - it speaks node identifiers and raw payloads, decoding the format's permute and cyclic content encodings transparently. Folder, message, and property semantics belong to the higher layers built on top of it.

Reads seek the source stream on demand; the file is never buffered whole. The session is single-threaded: its members must not be called concurrently.

using Bodu.IO.Pst;

using var file = PstFile.OpenRead("archive.pst");

foreach (PstNodeInfo info in file.EnumerateNodes())
    Console.WriteLine($"{info.NodeId} ({info.NodeId.Type}): {info.DataLength} bytes");

Properties

CryptMethod

Gets the content-encoding method applied to the file's block data.

public PstCryptMethod CryptMethod { get; }

Property Value

PstCryptMethod

The declared method; data is decoded transparently on read.

Exceptions

ObjectDisposedException

The session has been disposed.

Format

Gets the file's format variant.

public PstFileFormat Format { get; }

Property Value

PstFileFormat

Unicode or Ansi; the 4 KiB-page OST variant fails to open.

Exceptions

ObjectDisposedException

The session has been disposed.

Methods

Dispose()

Releases the session and, unless it was left open, the source stream.

public void Dispose()

EnumerateNodes()

Enumerates every node in the node B-tree, in identifier order.

public IEnumerable<PstNodeInfo> EnumerateNodes()

Returns

IEnumerable<PstNodeInfo>

The node directory facts, resolved lazily.

Exceptions

ObjectDisposedException

The session has been disposed.

PstFileFormatException

A tree page or block fails validation while walking.

GetNode(PstNodeId)

Retrieves a node by identifier.

public PstNode GetNode(PstNodeId id)

Parameters

id PstNodeId

The node identifier.

Returns

PstNode

The node.

Exceptions

ObjectDisposedException

The session has been disposed.

PstNodeNotFoundException

No node with the identifier exists.

IsPstFile(Stream)

Determines whether a stream begins with the PST magics; its position is restored before returning.

public static bool IsPstFile(Stream stream)

Parameters

stream Stream

The readable, seekable stream to sniff.

Returns

bool

true when the stream looks like a PST file of any variant.

Exceptions

ArgumentNullException

Thrown if stream is null.

Open(Stream, PstFileOptions, bool)

Opens a PST file from a stream with explicit options.

public static PstFile Open(Stream stream, PstFileOptions options, bool leaveOpen = false)

Parameters

stream Stream

The readable, seekable stream positioned at the file start.

options PstFileOptions

The reader options.

leaveOpen bool

true to leave the stream open when the session is disposed.

Returns

PstFile

The open session.

Exceptions

ArgumentNullException

Thrown if stream or options is null.

ArgumentException

The stream is not readable and seekable.

PstFileFormatException

The stream is not a structurally valid PST file.

PstUnsupportedFormatException

The file uses a recognized but unsupported variant.

OpenRead(Stream, bool)

Opens a PST file from a stream with default options.

public static PstFile OpenRead(Stream stream, bool leaveOpen = false)

Parameters

stream Stream

The readable, seekable stream positioned at the file start.

leaveOpen bool

true to leave the stream open when the session is disposed.

Returns

PstFile

The open session.

Exceptions

ArgumentNullException

Thrown if stream is null.

ArgumentException

The stream is not readable and seekable.

PstFileFormatException

The stream is not a structurally valid PST file.

PstUnsupportedFormatException

The file uses a recognized but unsupported variant.

OpenRead(string)

Opens a PST file from a path.

public static PstFile OpenRead(string path)

Parameters

path string

The file path.

Returns

PstFile

The open session.

Exceptions

ArgumentNullException

Thrown if path is null.

PstFileFormatException

The file is not a structurally valid PST file.

PstUnsupportedFormatException

The file uses a recognized but unsupported variant.

TryGetNode(PstNodeId, out PstNode)

Attempts to retrieve a node by identifier.

public bool TryGetNode(PstNodeId id, out PstNode node)

Parameters

id PstNodeId

The node identifier.

node PstNode

When this method returns true, the node.

Returns

bool

true when the node exists.

Exceptions

ObjectDisposedException

The session has been disposed.

Applies to

ProductVersions
.NET8, 10