如何使用MAPI获取Outlook联系人组?(How to get Outlook contact groups using MAPI?)
在Outlook 2010中,您可以创建联系人并将其添加到组。 有没有办法获得这些群组及其中的联系人列表? 以下是我访问联系人的方式:
var outlook = new Outlook.Application().GetNamespace("MAPI"); var folder = outlook.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts); foreach (var curr in folder.Items.OfType<Outlook.ContactItem>()) { ... }我不是指默认联系人文件夹,例如“联系人”和“建议的联系人”。
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".
最满意答案
联系人组由DistListItem接口表示。 DistListItem接口具有MemberCount属性和GetMember()方法来遍历组成员。
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); } }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); } }更多推荐
发布评论