WebDav WHERE Clause not finding mobile, telephoneNumber2 in AdvancedSearch()

D

dangordo

Hello -- I'm running an AdvancedSearch() of Outlook contacts using C#,
and I'm having a problem with the filter parameter (essentially a
WebDAV WHERE clause). The following code works well, except that I get
no results when searching on certain fields (mobile, telephoneNumber2;
see below). Can anyone help?

using System;
using System.Collections;
using System.Text;
using Outlook = Microsoft.Office.Interop.Outlook;

namespace GetNickname3
{
public static class OutlookSearch
{
//right now, just display all names
public static void findContacts(string phoneNumberToFind)
{
//open outlook and contacts folder
Outlook._Application olApp = new
Outlook.ApplicationClass();
Outlook._NameSpace olNS = olApp.GetNamespace("MAPI");
Outlook.MAPIFolder contacts =
olNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts);

//set advanced search events
olApp.Session.Application.AdvancedSearchComplete += new
Microsoft.Office.Interop.Outlook.ApplicationEvents_11_AdvancedSearchCompleteEventHandler(OnCompleteAdvanacedSearch);
//start search
startAdvancedSearch(olApp);

Console.ReadLine();
}

private static void startAdvancedSearch(Outlook._Application
olApp)
{
Outlook.Search s;
try
{
//set filter string
string filterStr = "";
filterStr = "urn:schemas:contacts:telephoneNumber like
'%212%'"; //works
filterStr = "urn:schemas:contacts:pager like '%212%'";
//works
filterStr = "urn:schemas:contacts:homePhone like
'%212%'"; //works
filterStr =
"urn:schemas:contacts:facsimiletelephonenumber like '%212%'"; //works
//filterStr = "urn:schemas:contacts:telephoneNumber2
like '%212%'"; //doesn't work
//filterStr = "urn:schemas:contacts:telephonenumber2
like '%212%'"; //doesn't work
//filterStr = "urn:schemas:contacts:mobile like
'%212%'"; //doesn't work

//start advanced search
s = olApp.AdvancedSearch("Contacts", filterStr, false,
"ContactsSearch");

}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
Console.WriteLine(ex.Data);
Console.WriteLine(ex.Source);
}
}

private static void OnCompleteAdvanacedSearch(Outlook.Search s)
{
Console.WriteLine("Complete");
Console.WriteLine(s.Results.Count);
foreach (object obj in s.Results)
{
if (obj is Outlook.ContactItem)
{
Outlook.ContactItem myCI =
(Outlook.ContactItem)obj;
Console.WriteLine(myCI.LastName + ", " +
myCI.FirstName + ": " + myCI.MobileTelephoneNumber);
}
}
}
}
}
 
B

Brian Tillman

Hello -- I'm running an AdvancedSearch() of Outlook contacts using C#,

Try asking in a programming newsgroup like
news://msnews.microsoft.com/microsoft.public.program_vba or
news://msnews.microsoft.com/microsoft.public.program_addins
 

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