CDO, Look for a Telephone Number using MessageFilter

  • Thread starter Thread starter mgarg
  • Start date Start date
M

mgarg

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;
oSession.Logon(vEmpty,vEmpty,false,false,vEmpty,vEmpty,vEmpty);
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 =
(MAPI.Field)fields.Add(MAPI.CdoPropTags.CdoPR_BUSINESS_TELEPHONE_NUMBER,vEmpty,"111111",vEmpty);
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
(MAPI.CdoPropTags.CdoPR_BUSINESS_TELEPHONE_NUMBER,vEmpty);
object obj = oField1.Value;
}
oSession.Logoff();

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
number.

Any help will be appreciated

Regards Mita
 
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
(MAPI.CdoPropTags.CdoPR_BUSINESS_TELEPHONE_NUMBER,"111111");

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 =
(MAPI.Field)fields.Add(MAPI.CdoPropTags.CdoPR_BUSINESS_TELEPHONE_NUMBER,"92");

Gives me a compile Error
No overload for method 'Add' takes '2' arguments
 
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 www.cdolive.com also only use 2 arguments and you
can't argue with Sig Weber's code for CDO.
 
Back
Top