Results 1 to 5 of 5

Thread: Trying to automate searching Outlook's address book and need optimization tips->

Threaded View

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2003
    Posts
    1,945

    Trying to automate searching Outlook's address book and need optimization tips->

    Hi,

    Looking for a way to quickly find e-mail addresses associated with a contact's name I wrote a program to do exactly this and it works fine except for the fact that when dealing with an addressbook containing 70000 or so contacts it's so slow that it takes several minutes to read the addressbook or to go through all the contacts collected to find an e-mail address.

    When the user selects an addressbook or an address entry type (Outlook.OlAddressEntryUserType) it collects all contacts that meet the criteria using the following code:

    Code:
     e.Result = (From Contact In .OutlookO.GetNamespace("MAPI").AddressLists(.AddressList).AddressEntries Where DirectCast(Contact, Outlook.AddressEntry).AddressEntryUserType = .AddressType Select DirectCast(Contact, Outlook.AddressEntry)).ToArray()
    "e.Result" refers to return value for the backgroundworker object used to execute the above code.

    "ContactsSource.Contacts" refers to an Outlook.AddressEntry array that is part of the public ContactsSource structure.

    Code:
             Dim EMailAddresses As New List(Of String)
             Dim FirstContact As Outlook.AddressEntry = Nothing
    
             Name = Name.Trim()
    
             If ContactsSource.Contacts.Count > 0 Then
                FirstContact = ContactsSource.Contacts.First
                If FirstContact.GetContact() IsNot Nothing Then
                   For Each Contact As Outlook.AddressEntry In From ContactO In ContactsSource.Contacts Where ContactO.GetContact().FullName.IndexOf(Name, StringComparison.CurrentCultureIgnoreCase) > -1
                      With Contact.GetContact()
                         EMailAddresses.AddRange({ .Email1Address, .Email2Address, .Email3Address})
                      End With
                   Next Contact
                ElseIf FirstContact.GetExchangeDistributionList() IsNot Nothing Then
                   For Each Contact As Outlook.AddressEntry In From ContactO In ContactsSource.Contacts Where ContactO.GetExchangeDistributionList.Name.IndexOf(Name, StringComparison.CurrentCultureIgnoreCase) > -1
                      EMailAddresses.Add(Contact.GetExchangeDistributionList.PrimarySmtpAddress)
                   Next Contact
                ElseIf FirstContact.GetExchangeUser() IsNot Nothing Then
                   For Each Contact As Outlook.AddressEntry In From ContactO In ContactsSource.Contacts Where ContactO.GetExchangeUser.Name.IndexOf(Name, StringComparison.CurrentCultureIgnoreCase) > -1
                      EMailAddresses.Add(Contact.GetExchangeUser.PrimarySmtpAddress)
                   Next Contact
                End If
    Does any one here know how to optimize the code so that it only takes seconds instead of minutes to go through a large number contacts? Any help would be appreciated.

    The full program code has been attached to this post as Sea.zip.

    Thanks in advance.
    Last edited by Peter Swinkels; Nov 2nd, 2017 at 01:54 PM. Reason: typo's

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width