Renaming a Folder
| Nik Okuntseff |
MS Exchange Server Programming |
Renaming a Folder
If you come across a need to rename a folder programmatically, the following
sample (Folders/RenameFolder) may help. Algorithm is very straightforward:
I open a folder and then use the HrSetOneProp function to change its PR_DISPLAY_NAME
property. I use the Drafts folder to rename it to MyDrafts. You need to
change the names according to your needs.
#include <afxwin.h>
#include <edk.h>
int main()
{
/*
* Algorithm:
* 1. Logon to MAPI and open message
store.
* 2. Locate and open the desired folder.
* 3. Call the HrSetOneProp to change
PR_DISPLAY_NAME
*/
// Change if necessary
char * pszFolder = "@PR_IPM_SUBTREE_ENTRYID\\Drafts";
HRESULT hr;
LPMAPISESSION pSession = NULL;
// Initialize MAPI
hr = MAPIInitialize(NULL);
if (FAILED(hr)) throw -1;
// Obtain MAPI session
hr = MAPILogonEx(0, // Handle
to parent window
"MS Exchange Settings", // Profile name
NULL, // Password
MAPI_NEW_SESSION |
MAPI_EXTENDED |
MAPI_LOGON_UI, // Logon flags
&pSession); // Resulting MAPI
session
if (FAILED(hr)) throw -1;
// Find default message store
ULONG cbDefStoreEid = 0;
LPENTRYID pDefStoreEid = NULL;
hr = HrMAPIFindDefaultMsgStore(pSession, &cbDefStoreEid,
&pDefStoreEid);
if (FAILED(hr)) throw -1;
// Open default message store
LPMDB pDefMsgStore = NULL;
hr = pSession->OpenMsgStore(0, cbDefStoreEid, pDefStoreEid,
NULL,
MDB_WRITE | MAPI_DEFERRED_ERRORS,
&pDefMsgStore);
if (FAILED(hr)) throw -1;
// Open the desired folder
LPMAPIFOLDER pFolder = NULL;
hr = HrMAPIOpenFolderEx(pDefMsgStore,
'\\',
pszFolder,
&pFolder);
if (FAILED(hr)) throw -1;
// Change its display name
SPropValue spv;
spv.ulPropTag = PR_DISPLAY_NAME;
spv.Value.lpszA = "MyDrafts";
hr = HrSetOneProp(pFolder, &spv);
if (FAILED(hr)) throw -1;
// Cleanup
if (pFolder)
pFolder->Release();
if (pDefMsgStore)
pDefMsgStore->Release();
if (pDefStoreEid)
MAPIFreeBuffer(pDefStoreEid);
if (pSession)
pSession->Release();
::MAPIUninitialize();
return 0;
}
[ Contents |
Home
]
Send comments and suggestions to niko@wrconsulting.com
Copyright © 1997-1998 by Nik Okuntseff
|