PstFile Class

An Outlook data file (PST or OST) opened for reading. The objects it returns read the file when they are accessed, so the file must stay open while they are used.

public sealed class PstFile : IDisposable

Remarks

The instances are not thread-safe: use one instance per thread.

Example

using var file = PstFile.Open(path);
Assert.Equal(PstFormat.Unicode, file.Format);
Assert.Equal("Outlook Data File", file.Store.DisplayName);

var folder = file.GetFolder("Inbox/tmp");
Assert.NotNull(folder);
Assert.Equal(4, folder.ContentCount);
Implements

Properties

NameDescription
EncryptionGets the method that obfuscates the data blocks of the file.
FormatGets the format of the file.
IsOfflineFileGets whether the file is an offline file (OST) of an Exchange or IMAP account, rather than a personal file (PST).
RootFolderGets the root folder of the file, which contains the top of the folder hierarchy and the search folders.
StoreGets the message store: the display name of the file and its root folder.

Encryption

PstFile.cs

Gets the method that obfuscates the data blocks of the file.

public PstEncryption Encryption { get; }

Property value

PstEncryption

Gets the format of the file.

public PstFormat Format { get; }

Property value

PstFormat

IsOfflineFile

PstFile.cs

Gets whether the file is an offline file (OST) of an Exchange or IMAP account, rather than a personal file (PST).

public bool IsOfflineFile { get; }

Property value

bool

RootFolder

PstFile.cs

Gets the root folder of the file, which contains the top of the folder hierarchy and the search folders.

public PstFolder RootFolder { get; }

Property value

PstFolder

Exceptions

InvalidEmailDataException
The file is malformed.

Gets the message store: the display name of the file and its root folder.

public PstStore Store { get; }

Property value

PstStore

Exceptions

InvalidEmailDataException
The file is malformed.

Methods

NameDescription
Dispose()Closes the file and the stream it reads, unless it was opened with leaveOpen.
GetFolder(string)Returns a folder from its path, the display names of the folders from the top of the folder hierarchy (or from the root folder when the first name is not found there), separated by /.
Open(byte[], PstReadOptions?)Opens a file from its content.
Open(Stream, PstReadOptions?, bool)Opens a file from a stream.
Open(string, PstReadOptions?)Opens a file.
Validate()Checks the structures of the whole file: the header, the B-trees, every block and every node, without stopping at the first error.

Dispose()

PstFile.cs

Closes the file and the stream it reads, unless it was opened with leaveOpen.

public void Dispose()

GetFolder(string)

PstFile.cs

Returns a folder from its path, the display names of the folders from the top of the folder hierarchy (or from the root folder when the first name is not found there), separated by /.

public PstFolder? GetFolder(string path)

Parameters

path string
The path of the folder, such as Inbox/Projects.

Returns

PstFolder? The folder, or null when no folder has this path.

Open overloads

Open(byte[], PstReadOptions?)

PstFile.cs

Opens a file from its content.

public static PstFile Open(byte[] data, PstReadOptions? options = null)
Parameters
data byte[]
The content of the file.
options PstReadOptions?
The options of the reader, or null for the default options.
Returns

PstFile The opened file.

Exceptions
InvalidEmailDataException
The data is not an Outlook data file or the file is malformed.
UnsupportedEmailFeatureException
The file uses a format version or an encryption method the library does not support.

Open(Stream, PstReadOptions?, bool)

PstFile.cs

Opens a file from a stream.

public static PstFile Open(Stream stream, PstReadOptions? options = null, bool leaveOpen = false)
Parameters
stream Stream
A readable and seekable stream.
options PstReadOptions?
The options of the reader, or null for the default options.
leaveOpen bool
true to leave the stream open when the file is disposed.
Returns

PstFile The opened file.

Exceptions
ArgumentException
The stream is not readable or not seekable.
InvalidEmailDataException
The stream does not contain an Outlook data file or the file is malformed.
UnsupportedEmailFeatureException
The file uses a format version or an encryption method the library does not support.

Open(string, PstReadOptions?)

PstFile.cs

Opens a file.

public static PstFile Open(string path, PstReadOptions? options = null)
Parameters
path string
The path of the file.
options PstReadOptions?
The options of the reader, or null for the default options.
Returns

PstFile The opened file.

Exceptions
InvalidEmailDataException
The file is not an Outlook data file or is malformed.
UnsupportedEmailFeatureException
The file uses a format version or an encryption method the library does not support.

Validate()

PstFile.cs

Checks the structures of the whole file: the header, the B-trees, every block and every node, without stopping at the first error.

Returns

IReadOnlyList<PstValidationIssue> The problems found; an empty list when the file is valid.