HOWTO: Create, Move, or Rename a Folder Using MAPI

ID: Q180232

The information in this article applies to:

SUMMARY

From time to time you may need to create, move, or rename a folder programmatically. This is done primarily through the IMAPIFolder and the IMAPIProp interfaces. The code example below walks you through the process of creating, moving, and renaming a folder.

MORE INFORMATION

General Steps (Applies to all three tasks)

1. Create a MAPI Session.

2. Get a pointer to the message store.

   NOTE: While the example below uses the private information store, the
   same logic and code can be used against the public information store.

3. Create, move, or rename a folder.

4. Log off and Release the session.

Creating a Folder

1. Create a pointer to the parent of the new folder. For example, if the

   new folder should be a subfolder to the mailbox, create a pointer to the
   top of the information store. If the new folder should be a subfolder of
   the Inbox, create a pointer to the Inbox.

2. Using the IMAPIFolder::CreateFolder, add the folder to the folder
   hierarchy.

Moving a Folder

1. Create a pointer to the folder that becomes the new parent of the folder

   being moved.

2. Using HrMAPIFindFolderEx(), retrieve the count of bytes and entry id of
   the folder you wish to move.

3. IMAPIFolder::CopyFolder with the entry id and count of bytes returned in
   the step above and FOLDER_MOVE in the ulFlags parameter moves the
   folder.

Renaming a folder

1. Using HrMAPIFindFolderEx(), retrieve the count of bytes and entry id of

   the folder you wish to rename.

2. Open the folder so that the properties of the folder can be changed.

3. Use HrSetOneProp() to change the PR_DISPLAY_NAME of the folder.

Code Example

The code example below demonstrates these three actions:

Keywords          : kbMsg kbMAPI100 
Version           : WINDOWS:1.0
Platform          : WINDOWS
Issue type        : kbhowto

Last Reviewed: February 5, 1998