MAPIFolder object

The MAPIFolder object allows you to work with Outlook folders. The Folders collection contains all of the folders contained in the namespace or the current folder.

Creating a new folder

Use the Add method from the Folders collection to add a new folder. You must specify the folder’s display name. Each folder also has a folder type that specifies the type of items that you can save in the folder. You can specify the default folder type with one of the following constants from the olDefaultFolders enumeration:










If you do not specify a constant, the folder type is set to the same type as the parent folder.

{Retrieve the default Inbox folder.}
folder = nameSpace.GetDefaultFolder(Outlook.olFolderInbox);
{Create a new folder named "House Matches" with the type of olFolderInbox.}
housesFolder = folder.Folders.Add("House Matches", Outlook.olFolderInbox);

The namespace contains a fixed list of default folders. You cannot add any additional folders to a namespace.

Retrieving an existing folder

You can retrieve a folder from the Folders collection with the Item method by the number associated with the folder.

{Retrieve the second folder from the Folders collection.}
folder = nameSpace.Folders.Item(2);

You can also a access folder by its display name.

{Retrieve the folder named "House Matches".}
housesFolder = folder.Folders.Item("House Matches");

You can also use the GetDefaultFolder method from the NameSpace object to retrieve the default folders. You must specify the folder item type with a constant from the olDefaultFolders enumeration.

{Retrieve the default contacts folder.}
folder = nameSpace.GetDefaultFolder(Outlook.olFolderContacts);

Setting and retrieving the display name

Use the Name property to set a folder’s display name.

{Set the display name of the folder.}
folder.Name = "Current Project";

You can also retrieve the folder’s display name with the Name property.

{Retrieve the display name of the folder.}
name = folder.Name;

Displaying a folder

Use the Display method to display a folder in a window.

{Display the folder.}

Retrieving the default item type

Use the DefaultItemType property to retrieve the default item type of the folder. The returned value is one of the constants in the olItemType enumeration.

{Retrieve the default item type for the folder.}
itemType = integer(folder.DefaultItemType);

Deleting a folder

Use the Delete method from the MAPIFolder object to delete a folder.

{Delete the folder.}

You can also use the Remove method to delete a folder from the Folders collection. You must supply the number associated with the folder.

{Delete the second folder from the Folders collection.}

Folders that are deleted are sent to the Deleted Items folder. However, if a folder is deleted from the Deleted Items folder, it is permanently deleted.

Documentation Feedback