如何使用MAPI获取Outlook联系人组?(How to get Outlook contact groups using MAPI?)

编程入门 行业动态 更新时间:2024-10-27 12:33:34
如何使用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); } }

更多推荐

本文发布于:2023-04-28 00:48:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1329228.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何使用   联系人   MAPI   Outlook   contact

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!