Problem with AdvancedSearchComplete with C# and ItemsCollection.Sort

P

piyush

My goal is to receive numbers from a different application, look up
the Contact name from Contacts folder and then display mails from that
person.

I am trying to use AdvancedSearch for name matching but facing
problems with C#. The reason I need AdvancedSearch is that Restrict
and Find do not have any wildcard characters and I need to take care
of multiple possibilities like say for Bill Gates it could be

"Bill Gates"
"Gates, Bill"
"Gates, Bill (IT)"
"Gates, Bill (HR)"
"Bill Gates (IT)"
"Bill Gates (HR)"

I was thinking of wildcard characters for
sFilter = "[SenderName] = 'Gates, Bill (??)'"

But I learn that wildcard characters are not supported with Restrict.

Now, where should the AdvancedSearchComplete code be put ? Should it
be a
function
in itself ? If so, what should be its name (in VBA, I saw
Application_AdvancedSearchComplete or
outlookobj_AdvancedSearchComplete in Randy Bryne's book).

Also, does urn:schemas:inbox:SenderName exist for me to search on
SenderName?

My code is as follows :

class blah {

private Outlook.ApplicationClass ola ;
private Outlook.Namespace olns

blah() //constructor
{
// all this constructor work is perfect
olns = ola.GetNamespace ;
.... (all these things seem to be fine)
}

public void func1()
{
Outlook.Search olsearch;
ola.Application.AdvancedSearch ("Inbox", "urn:schemas:inbox:SenderName
LIKE '%Bill%'", false, "complete")
}

public void AdvancedSearchComplete(Outlook.Search olsearch)
{
olresults = olsearch.Results;
for (int i = 1 ; i < olresults.Count ; i++)
{
Outlook._MailItem tempItem = (Outlook._MailItem)olresults.Item (i);
Console.Writeline (tempItem.Subject);
}
}//AdvancedSearchComplete
}//class

Obviously this doesnt work.

A different way to solve my problem is :

I have defined 3 search filters that cover all the cases matching the
SenderName (hence no need of wild characters and hence no need of
AdvancedSearch).

The problem is each of them is a different Restrict and hence each of
them is a differnet Items collection (ie)

"Bill Gates" returns results (in some random order apparently) in
colitems1
"Gates, Bill" returns results (in some random order apparently) in
colitems2

What I want to do is to sort the results and display the mails (from
either of the display names). For that I would need to have all the
items in a single collection (to sort them).

Any comments are highly appreciated.

Thanks !
Piyush
 

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