ContactCollection.Find - searching via multiple properties

  • Thread starter Thread starter farseer
  • Start date Start date
F

farseer

Hi,
Is there a way to search the ContactCollection by say FirstName,
LastName and PhoneNumber? it seems the Find method takes a
PropertyDescriptor which means you can only search via one property it
seems...unless i am missing something.

OutlookSession ol = new OutlookSession();
ContactCollection col = ol.Contacts.Items;
PropertyDescriptor prop =
TypeDescriptor.GetProperties(GetType(Contact)).Item("LastName");
int id = col.Find(prop, "Smith");

What happens if you have 5 "Smiths" in your contact? How can i specify
a more refined search here by searching by more than one property.
 
had a brilliant idea to use the Restrict method, but getting an
exception with the following code

col = col.Restrict( "[FirstName]='John' AND [LastName]='Smith'" );

error: "The query string is incorrectly formatted."
 
solved: with the restrict, need to use use double quotes (asci
34?)..so should look like:

col = col.Restrict( "[FirstName]=\"John\" AND [LastName]=\"Smith\"" );
 
Back
Top