PstFolder Class

A folder of an Outlook data file: its subfolders, its items and its associated (hidden) items.

public sealed class PstFolder

Example

using var file = PstFile.Open(path);
var subjects = new List<string>();
void Visit(PstFolder folder)
{
    foreach (var item in folder.EnumerateItems())
    {
        subjects.Add($"{folder.Path}: {item.Subject}");
    }

    foreach (var child in folder.Folders)
    {
        Visit(child);
    }
}

Visit(file.RootFolder);
Assert.Contains("Top of Outlook data file/Inbox/tmp: original email", subjects);

Properties

NameDescription
ContainerClassGets the class of the items the folder contains, such as IPF.Note (mail), IPF.Contact, IPF.Appointment or IPF.Task.
ContentCountGets the number of items, as stored in the folder.
DisplayNameGets the display name of the folder.
FoldersGets the subfolders.
HasSubfoldersGets whether the folder has subfolders, as stored in the folder.
IsSearchFolderGets whether the folder is a search folder, whose items are the results of a search in other folders.
NodeIdGets the identifier of the node of the folder in the file.
ParentGets the parent folder, or null for the root folder.
PathGets the path of the folder: the display names of the folders from the root folder (excluded), separated by /.
PropertiesGets the properties of the folder.
UnreadCountGets the number of unread items, as stored in the folder.

ContainerClass

PstFolder.cs

Gets the class of the items the folder contains, such as IPF.Note (mail), IPF.Contact, IPF.Appointment or IPF.Task.

public string? ContainerClass { get; }

Property value

string?

ContentCount

PstFolder.cs

Gets the number of items, as stored in the folder.

public int ContentCount { get; }

Property value

int

DisplayName

PstFolder.cs

Gets the display name of the folder.

public string? DisplayName { get; }

Property value

string?

Gets the subfolders.

public IReadOnlyList<PstFolder> Folders { get; }

Property value

IReadOnlyList<PstFolder>

Exceptions

InvalidEmailDataException
The hierarchy table of the folder is malformed.

HasSubfolders

PstFolder.cs

Gets whether the folder has subfolders, as stored in the folder.

public bool HasSubfolders { get; }

Property value

bool

IsSearchFolder

PstFolder.cs

Gets whether the folder is a search folder, whose items are the results of a search in other folders.

public bool IsSearchFolder { get; }

Property value

bool

Gets the identifier of the node of the folder in the file.

public uint NodeId { get; }

Property value

uint

Gets the parent folder, or null for the root folder.

public PstFolder? Parent { get; }

Property value

PstFolder?

Gets the path of the folder: the display names of the folders from the root folder (excluded), separated by /.

public string Path { get; }

Property value

string

Properties

PstFolder.cs

Gets the properties of the folder.

public MapiPropertyCollection Properties { get; }

UnreadCount

PstFolder.cs

Gets the number of unread items, as stored in the folder.

public int UnreadCount { get; }

Property value

int

Methods

NameDescription
EnumerateAssociatedItems()Enumerates the associated items of the folder: the hidden items that store views, rules or settings.
EnumerateItems()Enumerates the items of the folder (messages, contacts, appointments...). Each item is read when the enumeration reaches it. A search folder has no items when Outlook stores its results in a structure that [MS-PST] does not document.
GetFolder(string)Returns a subfolder from its display name, ignoring case.
ToString()Returns the display name of the folder.

EnumerateAssociatedItems()

PstFolder.cs

Enumerates the associated items of the folder: the hidden items that store views, rules or settings.

public IEnumerable<MapiMessage> EnumerateAssociatedItems()

Returns

IEnumerable<MapiMessage> The associated items.

Exceptions

InvalidEmailDataException
The associated contents table of the folder or an item is malformed.

EnumerateItems()

PstFolder.cs

Enumerates the items of the folder (messages, contacts, appointments...). Each item is read when the enumeration reaches it. A search folder has no items when Outlook stores its results in a structure that [MS-PST] does not document.

public IEnumerable<MapiMessage> EnumerateItems()

Returns

IEnumerable<MapiMessage> The items, as MapiMessage or one of its derived classes for the items Outlook types (MapiContact, MapiAppointment, MapiTask, MapiDistributionList).

Exceptions

InvalidEmailDataException
The contents table of the folder or an item is malformed.

GetFolder(string)

PstFolder.cs

Returns a subfolder from its display name, ignoring case.

public PstFolder? GetFolder(string name)

Parameters

name string
The display name of the subfolder.

Returns

PstFolder? The subfolder, or null when the folder has no subfolder with this name.

ToString()

PstFolder.cs

Returns the display name of the folder.

public override string ToString()

Returns

string The display name of the folder.