Searching outlook folders

J

John

Hi

I am using the following code to search for an email message with id myID;

Dim SentFld As Outlook.MAPIFolder
Dim Email As Outlook.MailItem
Dim I As Integer
OutlookApp = New Outlook.Application

SentFld =
OutlookApp.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderSentMai
l)
iCount = SentFld.Items.Count
Email = CType(SentFld.Items.Item(1), Outlook.MailItem)
Email.UserProperties.Add("EmailID", Outlook.OlUserPropertyType.olText, True)
Email = SentFld.Items.Find("[EmailID]=""" & myID & """")

The problem is that the find is very slow. Is there a faster way to search
for emails with specific user defined ids?

Thanks

Regards
 
C

Cor

Hi John,
I remember me that I had the same problem a very long time ago.

But then I thougth the problem was the time to load the folder over the
network and not the search, I had no solution, but can it be this is the
same problem?

I know it does not help, but I ask this to get it easier for others to help
you, and then maybe I know the solution too then.

Cor
 
T

Tom Rizzo [MSFT]

You could try the restrict method rather than the find method. Also,
Outlook has unique ID's on every item called the EntryID (or ID on the
mailitem). You may just want to store and use that ID which will be much
faster to find using the built-in methods for finding via ID.

Tom
 
D

Dmitry Streblechenko

Keep in mind that you can kill your Exchange server if you are using
Restrict rather than Find/FindNext - Exchange caches restrictions for about
1 week by default and updates the restriction results everytime any message
in the folder changes.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool


Tom Rizzo said:
You could try the restrict method rather than the find method. Also,
Outlook has unique ID's on every item called the EntryID (or ID on the
mailitem). You may just want to store and use that ID which will be much
faster to find using the built-in methods for finding via ID.

Tom

--
Looking for a good book on programming Exchange, Outlook, ADSI and
SharePoint? Check out http://www.microsoft.com/MSPress/books/5517.asp

This posting is provided "AS IS" with no warranties, and confers no rights.



John said:
Hi

I am using the following code to search for an email message with id myID;

Dim SentFld As Outlook.MAPIFolder
Dim Email As Outlook.MailItem
Dim I As Integer
OutlookApp = New Outlook.Application

SentFld =
OutlookApp.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderSentMai
l)
iCount = SentFld.Items.Count
Email = CType(SentFld.Items.Item(1), Outlook.MailItem)
Email.UserProperties.Add("EmailID", Outlook.OlUserPropertyType.olText, True)
Email = SentFld.Items.Find("[EmailID]=""" & myID & """")

The problem is that the find is very slow. Is there a faster way to search
for emails with specific user defined ids?

Thanks

Regards
 

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