The DeleteFolder method removes a subfolder from the current folder.
HRESULT DeleteFolder ( ULONG cbEntryID, LPENTRYID lpEntryID, ULONG ulUIParam, LPMAPIPROGRESS lpProgress, ULONG ulFlags );
[in] Count of bytes in the entry identifier pointed to by lpEntryID.
[in] Reference to an ENTRYID structure that represents the entry identifier of the subfolder to delete; cannot be NULL.
[in] Bitmask of flags that controls the deletion of the subfolder. The following flags can be set:
All subfolders of the subfolder pointed to by lpEntryID should be deleted. The method will fail if the subfolder being deleted contains subfolders and this flag is not set.
All messages in the subfolder pointed to by lpEntryID should be deleted. The method will fail if the subfolder being deleted contains messages and this flag is not set.
This method returns the standard values E_INVALIDARG, E_OUTOFMEMORY, E_UNEXPECTED, and E_FAIL, as well as the following:
The subfolder being deleted contains subfolders, and the DEL_FOLDERS flag was not set. The subfolder was not deleted.
The subfolder being deleted contains messages, and the DEL_MESSAGES flag was not set. The subfolder was not deleted. However, if the DEL_FOLDERS flag was set, some empty subfolders (within the subfolder being deleted) may have been deleted.
Folders to be deleted must be located in the folder designated as the special wastebasket folder, typically the Deleted Items folder in the interpersonal message (IPM) subtree. By default, DeleteFolder operates only on empty folders, but it can be used successfully on non-empty folders by setting two flags: DEL_FOLDERS and DEL_MESSAGES. Only empty folders or folders that set both the DEL_FOLDERS and DEL_MESSAGES flags on the DeleteFolder call can be deleted. DEL_FOLDERS enables all of the folder's subfolders to be removed; DEL_MESSAGES enables all of the folder's messages to be removed.
When DeleteFolder is called on a folder that is not in the wastebasket, the method moves the folder to the wastebasket. In this case, the ulFlags value is ignored.
When DeleteFolder is unable to complete, do not assume that no work was done. DeleteFolder might have been able to delete one or more of the messages and subfolders before encountering the error.