Correct way to get top-level folder of newly added store (new PST file)

  • Thread starter Thread starter sshock
  • Start date Start date
S

sshock

I need to know how to get the top-level folder for the store that I
just opened/created with AddStore. My code looks like this right now:

.... (create olApp object) ...
CNameSpace olNs(olApp.GetNamespace("MAPI"));
olNs.AddStore(COleVariant(CString("C:\\plhtest.pst")));
CFolders folders = olNs.get_Folders();
CMAPIFolder folder = folders.GetLast();
.... (do stuff with folder) ...
olNs.RemoveStore(folder);

Is that the correct way to get the folder? I read somewhere that you
aren't guaranteed that the last folder is the right one for the store
you just added, but if not, what is the right way? The AddStore
function doesn't have a return value!

Thanks,
Phillip Hellewell
 
You shouldn't assume that the latest added will the "last." Instead, maintain an array of the StoreID values for all the current stores, then use GetLast and see if its StoreID is in the array. If it isn't, then you have the right store. If it is in the array, try again with GetPrevious.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
Sue said:
You shouldn't assume that the latest added will the "last." Instead, maintain an array of the StoreID values for all the current stores, then use GetLast and see if its StoreID is in the array. If it isn't, then you have the right store. If it is in the array, try again with GetPrevious.

Thank you. While this isn't as straightforward as I had hoped for, it
is doable.

Phillip
 
Back
Top