PstFile Class
Definition
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
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
idPstNodeIdThe 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
streamStreamThe readable, seekable stream to sniff.
Returns
Exceptions
- ArgumentNullException
Thrown if
streamis 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
streamStreamThe readable, seekable stream positioned at the file start.
optionsPstFileOptionsThe reader options.
leaveOpenbooltrue to leave the stream open when the session is disposed.
Returns
- PstFile
The open session.
Exceptions
- ArgumentNullException
Thrown if
streamoroptionsis 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
streamStreamThe readable, seekable stream positioned at the file start.
leaveOpenbooltrue to leave the stream open when the session is disposed.
Returns
- PstFile
The open session.
Exceptions
- ArgumentNullException
Thrown if
streamis 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
pathstringThe file path.
Returns
- PstFile
The open session.
Exceptions
- ArgumentNullException
Thrown if
pathis 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
Returns
Exceptions
- ObjectDisposedException
The session has been disposed.
Applies to
| Product | Versions |
|---|---|
| .NET | 8, 10 |