在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>())
{
...
}
我不表示默认联系人文件夹,例如“通讯录”和“推荐的联系人”。
答案 0 :(得分:6)
联系人群组由DistListItem Interface表示。 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);
}
}
答案 1 :(得分:0)
你可以尝试这个
DataTable dt = new DataTable();
dt.Columns.Add("FirstName");
dt.Columns.Add("MiddleName");
dt.Columns.Add("LastName");
dt.Columns.Add("Email");
Microsoft.Office.Interop.Outlook.Items OutlookItems;
Microsoft.Office.Interop.Outlook.Application outlookObj = new Microsoft.Office.Interop.Outlook.Application();
MAPIFolder Folder_Contacts = (MAPIFolder)outlookObj.Session.GetDefaultFolder(OlDefaultFolders.olFolderContacts);
OutlookItems = Folder_Contacts.Items;
foreach (var item in OutlookItems)
{
var contact = item as ContactItem;
if (contact != null)
{
DataRow dr = dt.NewRow();
dr["FirstName"] = contact.FirstName;
dr["MiddleName"] = contact.MiddleName;
dr["LastName"] = contact.LastName;
dr["Email"] = contact.Email1Address;
dt.Rows.Add(dr);
}
}