Creating a Folder

This procedure can be used for creating a folder in the public, private, or personal information stores. You cannot create subfolders in the Favorites container of the public information store.

    To create a folder
  1. Open the information store. This returns an LPMDB pointer to the open information store. See Opening an Information Store.
  2. Open the folder in which you want to create a new folder by calling the IMsgStore::OpenEntry method, with the MAPI_MODIFY flag set. This folder will be the container of the folder you are creating.
  3. Create the folder with a call to the IMAPIFolder::CreateFolder method. This creates the subfolder object and returns an LPMAPIFOLDER pointer to it, which gives access to the IMAPIFolder interface on the new object.
  4. Optionally, set the folder’s PR_STATUS property to indicate a user-defined value. Use IMAPProp::SetProps to set this property.

The following sample code illustrates this procedure:

// Open the parent (or root) folder...
hr = lpMsgStore->OpenEntry(
    cbEID,    // use 0L for root folder
    lpEID,    // use NULL for root folder
    NULL,     // use NULL for interface ID
    MAPI_MODIFY | MAPI_DEFERRED_ERRORS, // use MAPI_MODIFY if 
    you plan to make changes
    &ulObjType,
    (LPUNKNOWN*)&lpParentFolder);

//  Create folder with MAPI call...
hr = lpParentFolder->CreateFolder(
    FOLDER_GENERIC,
    TEXT("Folder Name"),
    TEXT("Folder Comment"),
    NULL,        // Interface ID, must be NULL for client apps
    fMapiUnicode,
    &lpNewFolder);

// At this point you may set the folder's PR_STATUS property.
// It is purely optional, and may be any value you find meaningful.
static SPropValue PropStatus = { PR_STATUS, 0L, {0L}};
SPropProblemArray lpProblems = NULL;

hr = lpNewFolder->SetProps( 1, &PropStatus, &lpProblems);