Platform SDK: CDO 1.2.1

GetFolder Method (Session Object)

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

Syntax

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

objFolder
On successful return, contains the Folder object with the specified identifier. When the folder does not exist, GetFolder returns Nothing.
objSession
Required. The Session object.
folderID
Required. String that specifies the unique identifier of the folder. When you provide an empty string, some providers return the root folder.
storeID
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.

Remarks

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

For some message stores, you can obtain the store’s 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 store’s root folder differs from the IPM root folder. The store’s 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 object’s RootFolder property. You can obtain the store’s root folder through the IPM root folder’s 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 object’s 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.

Example

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) 
    Else 
        Set objFolder = objSession.GetFolder(folderID:=strFolderID, _ 
                                            storeID:=strFolderStoreID) 
    End If 
    If objFolder Is Nothing Then 
        Set objMessages = Nothing 
        MsgBox "Unable to retrieve folder with specified ID" 
        Exit Function 
    Else 
        Set objMessages = objFolder.Messages 
        MsgBox "Folder set to " & objFolder.Name 
    End If