搜索全球地址列表

时间:2011-12-01 05:48:54

标签: asp.net vb.net office-interop outlook-2010

有没有办法只在GAL中搜索联系人的givenName或LastName或emailaddress?目前我有这些代码:

Private Sub QuickSearch() 'Working!
    Dim oApp As New Outlook.Application
    Dim eu As Outlook.ExchangeUser = oApp.GetNamespace("MAPI").AddressLists("Global Address List").AddressEntries("Justin Timberlake").GetExchangeUser()
    If Not eu Is Nothing Then
        response.write(eu.Name + ": " + eu.Alias + ", " + eu.FirstName + ", " + eu.LastName + ", " + eu.MobileTelephoneNumber + ", " + eu.Department + ", " + eu.PrimarySmtpAddress)
    End If
    oApp.Quit()
End Sub

嗯,这个就像通过AddressList GAL进行快速搜索一样。但是出现了一个问题,例如我有这些联系人姓名:

- Justin Bieber

- Justin Timberlake

我搜索了 Justin ,只有 Justin Bieber 才会成为结果,因为这是第一个在列表中看到的内容。

1 个答案:

答案 0 :(得分:0)

您需要在AddressEntries处停止然后遍历列表

    Dim oApp As New Outlook.Application
    Dim aeList As Outlook.AddressEntries = oApp.GetNamespace("MAPI").AddressLists("Global Address List").AddressEntries("Justin Timberlake")
    If Not aeList Is Nothing Then
        For Each ae As Outlook.AddressEntry aeList
            Dim eu As Outlook.ExchangeUser = ae.GetExchangeUser()
            response.write(eu.Name + ": " + eu.Alias + ", " + eu.FirstName + ", " + eu.LastName + ", " + eu.MobileTelephoneNumber + ", " + eu.Department + ", " + eu.PrimarySmtpAddress)
        Next
    End If