Find Contact Problem

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
 
P

Peter Foot [MVP]

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
 
J

Jogi

Hi Peter,

thank you. Now I check the ContactCollection first, and it works.

Regards, Jogi
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top