In Outlook 2010, you can create contacts and add them to groups. Is there any way to get the list of such groups and the contacts in them? Here's how I access the contacts:
var outlook = new Outlook.Application().GetNamespace("MAPI");
var folder = outlook.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts);
foreach (var curr in folder.Items.OfType<Outlook.ContactItem>())
{
...
}
I do not mean default contact folders, such as "Contacts" and "Suggested contacts".
The contact groups are represented by DistListItem Interface. DistListItem
interface has MemberCount
property and GetMember()
method to iterate through the group members.
var outlook = new Application().GetNamespace("MAPI");
var folder = outlook.GetDefaultFolder(OlDefaultFolders.olFolderContacts);
foreach (var curr in folder.Items.OfType<DistListItem>())
{
Console.WriteLine(curr.DLName);
for (int memberIdx = 1; memberIdx <= curr.MemberCount; memberIdx++)
{
var member = curr.GetMember(memberIdx);
Console.WriteLine(member.Name);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With