How to: Display a Dialog Box for Selecting Entries from the Contacts Folder

本文介绍如何使用Outlook的SelectNamesDialog对象来显示来自联系人文件夹的条目,提供VBA及C#示例代码,适用于需要在应用程序中集成Outlook联系人选择功能的开发者。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

该篇文章是我于2009年6月10日通过自己编写的工具,批量从位于在博客园的博客站点(http://chenxizhang.cnblogs.com)同步而来。文章中的图片地址仍然是链接到博客园的。特此说明!

陈希章

原文地址:http://www.cnblogs.com/chenxizhang/archive/2008/06/11/1217094.html
原文标题:How to: Display a Dialog Box for Selecting Entries from the Contacts Folder
原文发表:2008/6/10 23:28:00

Outlook Developer Reference

This topic describes how to use the SelectNamesDialog object to display entries from the Contacts folder in a dialog box that resembles the Select Names dialog box in the Outlook user interface.

  1. Look for the address list that corresponds with the Contacts folder.

    The SelectNamesDialog object displays entires in a dialog box based on an AddressList. To display entries in the Contacts folder, look for the AddressList that corresponds with the Contacts folder. Iterate through all the address lists defined for the current session, and for each address list, use AddressList.GetContactsFolder to match the corresponding folder with the Contacts folder.

  2. Initialize the dialog box with the address list of the Contacts folder.
  3. Use SelectNamesDialog.Display to display the dialog box. If SelectNamesDialog.Display returns True, then selected entries will be available in SelectNamesDialog.Recipients.
Sub ShowContactsInDialog()
    Dim oDialog As SelectNamesDialog
    Dim oAL As AddressList
    Dim oContacts As Folder
    
    Set oDialog = Application.Session.GetSelectNamesDialog
    Set oContacts = _
        Application.Session.GetDefaultFolder(olFolderContacts)

    'Look for the address list that corresponds with the Contacts folder
    For Each oAL In Application.Session.AddressLists
        If oAL.GetContactsFolder = oContacts Then
            Exit For
        End If
    Next
    With oDialog
        'Initialize the dialog box with the address list representing the Contacts folder
        .InitialAddressList = oAL
        .ShowOnlyInitialAddressList = True
        If .Display Then
            'Recipients Resolved
            'Access Recipients using oDialog.Recipients
        End If
    End With
End Sub

See Also

 

下面是用C#的例子

//取得这个类的实例
Outlook.SelectNamesDialog dialog = Application.Session.GetSelectNamesDialog();
//是否允许多选
dialog.AllowMultipleSelection = true;

//取得联系人文件夹
Outlook.Folder contractFolder = Application.Session.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderContacts) as Outlook.Folder;

Outlook.AddressList oal=null;
//取得地址列表
foreach (Outlook.AddressList al in Application.Session.AddressLists)
{
    if (al.GetContactsFolder() == contractFolder)
    {
        oal = al;
        break;
    }
}

//初始化
dialog.InitialAddressList = oal;
dialog.ShowOnlyInitialAddressList = true;

//如果用户选择了某些收件人
if (dialog.Display())
{
    foreach (Outlook.Recipient rpt in dialog.Recipients)
    {
        //这里对选取的收件人列表做处理
        MessageBox.Show(rpt.AddressEntry.Name+","+rpt.AddressEntry.Address);  
    }
}

作者:陈希章
出处:http://blog.youkuaiyun.com/chen_xizhang
本文版权归作者所有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值