DistList members are not resolved if the contact is not in default folder

C

cbukeo

Hello All,
I am developing an Outlook 2007 addin using VisualStudio 2008 and C#. My goal
is to create a distList inside a contacts folder which is not the default
contacts folder. When I say "default contacts folder" I refer to the one
inside "Personal Folders". I successfully create the distribution list and
add members to it. However I am not able to resolve the contact and as a
result the member name shows same as the member e-mail address.
When I investigate this using redemption I noticed that there is a high level
"IAddrBook" button which brings up a list of the contacts inside default
contacts folder. And then there is a "IMAPIFolder" button which brings up a
dialog box with many tabs. One of these tabs is "GetContentsTable" which
lists the contacts that are not resolved correctly. I believe I have spotted
the problem but I could not figure out how I can tell outlook object model to
resolve the distList members from the "IMAPIFolder".
My code looks like this (a bit simplified):
using Outlook = Microsoft.Office.Interop.Outlook;

Outlook.Folder olFolder = olParentFolder.Folders.Add("AContactFolder",
OlDefaultFolders.olFolderContacts);

Outlook.DistListItem olDistList = olFolder.Items.Add(OlItemType.
olDistributionListItem);
Outlook.Recipient olRecipient = olFolder.Session.CreateRecipient(emailAddress)
;
foreach(emailAddress in emailAddressList)
{
if(olRecipient.Resolve())
{
olDistList.AddMember;
}
}

Thanks in advance
 
D

Dmitry Streblechenko

That folder must be used by OAB for the name resolution to work - set the
MAPIFolder.ShowAsOutlookAB property to true.

--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
 
C

cbukeo via OfficeKB.com

Thanks Dmitry,

Your suggestion and creating the distlist member with the name (instead of e-
mail address) solved the problem! For the benefit of the community fix is:

using Outlook = Microsoft.Office.Interop.Outlook;

Outlook.Folder olFolder = olParentFolder.Folders.Add("AContactFolder",
OlDefaultFolders.olFolderContacts);
olFolder.ShowAsOutlookAB = true;

Outlook.DistListItem olDistList = olFolder.Items.Add(OlItemType.
olDistributionListItem);
foreach(contactName in contactNameList)
{
Outlook.Recipient olRecipient = olFolder.Session.CreateRecipient
(contactName);
if(olRecipient.Resolve())
{
olDistList.AddMember;
}
}
 

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

Top