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

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
 
S

Sue Mosher [MVP-Outlook]

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
 
S

sshock

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Avoid login dialog 1

Top