SetSearchPath? Not Really
This is a follow up to our documentation on PR_AB_CHOOSE_DIRECTORY_AUTOMATICALLY. There, we discussed how Outlook 2010 has a property which can override the container specified in SetDefaultDir. Today, we’re going to override SetSearchPath. Let’s look at our dialog again:
That list of address books under Custom is what we set using SetSearchPath. How can we set “Start with Global Address List” or “Start with contact folders”? There’s a prop for that: PR_AB_SEARCH_PATH_CUSTOMIZATION, which you’ll find in the same place as PR_AB_CHOOSE_DIRECTORY_AUTOMATICALLY, on the profile section IID_CAPONE_PROF.
Here's the property definition:
#define PR_AB_SEARCH_PATH_CUSTOMIZATION( PT_LONG, 0x3D1B)
Here are the valid settings:
typedef enum _SearchPathReorderType
{
SEARCHPATHREORDERTYPE_RAW = 0,
SEARCHPATHREORDERTYPE_ACCT_PREFERGAL,
SEARCHPATHREORDERTYPE_ACCT_PREFERCONTACTS,
} SearchPathReorderType;
Finally, here's a description of each of the settings:
SEARCHPATHREORDERTYPE_RAW:
Return a list of the containers that are in the persisted MAPI search path. This is the "Custom" search path option in the UI.
SEARCHPATHREORDERTYPE_ACCT_PREFERGAL:
Group the search path based on the mail accounts in the profile, prefer the given sending account, and within each account, prefer the GAL. An example reordering here sending from account B would be the following:
Persisted search Path:
Contacts A
GAL A
GAL B
GAL C
Contacts D
Contacts D2
Contacts C
Contacts B
Reordered Search Path sending from B with this option:
GAL B
Contacts B
GAL A
Contacts A
GAL C
Contacts C
Contacts D
Contacts D2
SEARCHPATHREORDERTYPE_ACCT_PREFERCONTACTS
Group the search path based on the mail accounts in the profile, prefer the given sending account, and within each account, prefer that account's contacts folders. An example reordering here sending from account B would be the following:
Persisted search Path:
Contacts A
GAL A
GAL B
GAL C
Contacts D
Contacts D2
Contacts C
Contacts B
Reordered Search Path sending from B with this option:
Contacts B
GAL B
Contacts A
GAL A
Contacts C
GAL C
Contacts D
Contacts D2
Enjoy!
Comments
Anonymous
November 21, 2011
The comment has been removedAnonymous
November 22, 2012
The comment has been removedAnonymous
November 25, 2012
You left out the &: if (FAILED ( hRes = lpSession->OpenProfileSection((LPMAPIUID)&IID_CAPONE_PROF, NULL, MAPI_MODIFY, &lpProfSect)))Anonymous
November 28, 2012
Hello, and thanks for your answer. I get this error when I try with the syntax with "&IID_CAPONE_PROF"
1>ChangeAddressBookListOrder32.obj : error LNK2001: symbole externe non résolu _IID_CAPONE_PROF 1>C:ChangeAddressBookListOrder32DebugChangeAddressBookListOrder32.exe : fatal error LNK1120: 1 externes non résolus
have you an idea ? Thanks Jean
Anonymous
November 28, 2012
That's discussed here: support.microsoft.com/.../130869Anonymous
November 29, 2012
Hello, I have another question. The code works well when user has at least selects one time the radio button "Custom". But if it's a new profile, the is an error on "HrGetOneProp(lpProfSect,PR_AB_SEARCH_PATH_CUSTOMIZATION, &lpPropValue)". How can I initialise this property the first time ? Thanks JeanAnonymous
November 30, 2012
I found the solution for my last question. Here the code if someone have the same problem. Thanks Jean if (FAILED ( hRes = HrGetOneProp(lpProfSect,PR_AB_SEARCH_PATH_CUSTOMIZATION, &lpPropValue))) { printf ("Fatal Error: failed to get property PR_AB_SEARCH_PATH_CUSTOMIZATION %d try to creat a new one n",hRes); SPropValue spvEID_Ex; spvEID_Ex.ulPropTag = PR_AB_SEARCH_PATH_CUSTOMIZATION; spvEID_Ex.Value.l = 0; if (FAILED ( hRes = HrSetOneProp(lpProfSect, &spvEID_Ex))) { printf ("Fatal Error: failed to create a new one %d n",hRes); lngReturn = -11; goto Cleanup; } }Anonymous
May 15, 2015
Hello Stephen Griffin, I am new to this and just wondering if there is equivalent code in C#.NET that we can use to implement similar functionality. Please advise.