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 : IDisposableRemarks
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
| Name | Description |
|---|---|
| Encryption | Gets the method that obfuscates the data blocks of the file. |
| Format | Gets the format of the file. |
| IsOfflineFile | Gets whether the file is an offline file (OST) of an Exchange or IMAP account, rather than a personal file (PST). |
| RootFolder | Gets the root folder of the file, which contains the top of the folder hierarchy and the search folders. |
| Store | Gets the message store: the display name of the file and its root folder. |
Encryption
PstFile.csGets the method that obfuscates the data blocks of the file.
public PstEncryption Encryption { get; }Property value
Format
PstFile.csIsOfflineFile
PstFile.csRootFolder
PstFile.csGets the root folder of the file, which contains the top of the folder hierarchy and the search folders.
public PstFolder RootFolder { get; }Store
PstFile.csGets the message store: the display name of the file and its root folder.
public PstStore Store { get; }Methods
| Name | Description |
|---|---|
| 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.csCloses the file and the stream it reads, unless it was opened with leaveOpen.
public void Dispose()GetFolder(string)
PstFile.csReturns 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 /.
Parameters
pathstring- 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.csOpens a file from its content.
public static PstFile Open(byte[] data, PstReadOptions? options = null)Parameters
databyte[]- The content of the file.
optionsPstReadOptions?- The options of the reader, or
nullfor 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.csOpens a file from a stream.
public static PstFile Open(Stream stream, PstReadOptions? options = null, bool leaveOpen = false)Parameters
streamStream- A readable and seekable stream.
optionsPstReadOptions?- The options of the reader, or
nullfor the default options. leaveOpenbooltrueto 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.csOpens a file.
public static PstFile Open(string path, PstReadOptions? options = null)Parameters
pathstring- The path of the file.
optionsPstReadOptions?- The options of the reader, or
nullfor 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.csChecks the structures of the whole file: the header, the B-trees, every block and every node, without stopping at the first error.
public IReadOnlyList<PstValidationIssue> Validate()Returns
IReadOnlyList<PstValidationIssue> The problems found; an empty list when the file is valid.