GetFolder Method (Session Object)

GetFolder Method (Session Object)

The GetFolder method returns a Folder object from a MAPI message store.


Set objFolder = objSession.GetFolder(folderID [, storeID] )


On successful return, contains the Folder object with the specified identifier. When the folder does not exist, GetFolder returns Nothing.


Required. The Session object.


Required. String that specifies the unique identifier of the folder. When you provide an empty string, some providers return the root folder.


Optional. String that specifies the unique identifier of the message store containing the folder. The default value is an empty string, which corresponds to the default message store.


The GetFolder method allows you to obtain any Folder object for which you know the identifier, that is, the folders ID property.

For some message stores, you can obtain the stores root folder by supplying an empty string as the value for folderID. If the message store does not support returning its root folder, the call returns the error value CdoE_NOT_FOUND.

Note that the stores root folder differs from the IPM root folder. The stores root folder is the parent of the root folder of the the IPM subtree. The IPM subtree contains all interpersonal messages in a hierarchy of folders. Interpersonal messages are those whose message class starts with IPM, such as IPM.Note.

You can obtain the IPM root folder with the InfoStore objects RootFolder property. You can obtain the stores root folder through the IPM root folders FolderID property.

If your application is running as a Microsoft® Windows NT® service, you cannot access the Microsoft Exchange Public Folders through the normal hierarchy because of a notification conflict. You must use the InfoStore objects Fields property to obtain the Microsoft Exchange property PR_IPM_PUBLIC_FOLDERS_ENTRYID, property tag &H66310102. This represents the top-level public folder and allows you to access all other public folders through its Folders property.


This code fragment uses the GetFolder method to obtain a specific folder from a MAPI message store:

' from the function Session_GetFolder
' requires a global variable that contains the folder ID
' uses a global variable that contains the message store ID if present
    If strFolderID = "" Then
        MsgBox ("Must first set string variable to folder ID")
        Exit Function
    End If
    If strFolderStoreID = "" Then ' maybe get root folder
        Set objFolder = objSession.GetFolder(strFolderID)
        Set objFolder = objSession.GetFolder(folderID:=strFolderID, _
    End If
    If objFolder Is Nothing Then
        Set objMessages = Nothing
        MsgBox "Unable to retrieve folder with specified ID"
        Exit Function
        Set objMessages = objFolder.Messages
        MsgBox "Folder set to " & objFolder.Name
    End If

See Also


Session Object