CDO, Look for a Telephone Number using MessageFilter



Hi All,

All i am trying to is look for a particular Telephone number in
Contacts using MessageFilter instead of going through each message in
Contacts to speed up the search process. Can anyone help me in how to
do this.
Preferrably in c# but vb will also do.

This is how my code looks like
MAPI._Session oSession = new MAPI.Session();
Object vEmpty = Missing.Value;
MAPI.Folder oFolder = (MAPI.Folder)oSession.GetDefaultFolder(5);
MAPI.Messages oMessages = (MAPI.Messages)oFolder.Messages;
MAPI.MessageFilter oFilter = (MAPI.MessageFilter)oMessages.Filter;
MAPI.Fields fields = (MAPI.Fields)oFilter.Fields;
MAPI.Field oField =
for (int i = 1; i < Convert.ToInt32(oMessages.Count); i ++)
MAPI.Message oMessage = (MAPI.Message)oMessages.get_Item(i);
MAPI.Fields oFields = (MAPI.Fields)oMessage.Fields;
MAPI.Field oField1 = (MAPI.Field)oFields.get_Item
object obj = oField1.Value;

This For Loop goes through each of my messages in contacts. I was
thinking it will loop only twice if i have two messages with the same

Any help will be appreciated

Regards Mita

Ken Slovak - [MVP - Outlook]

With a message filter you'd just add the field's property tag and the value
you want to search for:

MAPI.Field oField = (MAPI.Field)fields.Add

You also may have other problems since the use of CDO 12.1 is not supported
in .NET code.


But using this line in .Net

MAPI.Field oField =

Gives me a compile Error
No overload for method 'Add' takes '2' arguments

Ken Slovak - [MVP - Outlook]

As I said, use of CDO 1.21 is not supported in .NET code. When I create a
CDO message filter I only use the 2 arguments and it's always worked. The
filtering examples at also only use 2 arguments and you
can't argue with Sig Weber's code for CDO.