Find Contact Problem

  • Thread starter Thread starter Jogi
  • Start date Start date
J

Jogi

Hello,

i want find a Contact with the BusinessTelephoneNumber. When I try
this:

OutlookSession os = new OutlookSession();

string callerId = "+49xxxxxxxxxxxxx";

string res = "[BusinessTelephoneNumber]=\"" + callerId + "\"";

Contact c = os.Contacts.Items.Restrict(res)[0];

if (c != null)
{
//found
}

I got an System.ArgumentOutOfRangeException, The indicated argument
lies outside of the valid range of values.

Need help, please

Thanks, Jogi
 
The reason for the exception is that you are retrieving element 0 from the
returned ContactCollection without checking if the Collection actually
contains any records first. A simple reason why it might not have is that
the number is not stored in the contact in the same way as it is from your
caller id. For example say your contact contains
+49 (0) xxxxxxxxxxxxxx
Which is still valid, but because it's not an exact match the Restrict
operation returns no results.

Peter
 
Back
Top