outlook items "addition time"

H

hsuntn

I am grabbing Outlook MailItems using the Items[] property on my
Outlook inbox. When I iterate through them, I notice that they are
not ordered in ReceivedTime or CreationTime order. For example,

Items[2].ReceivedTime is April 2005
Items[3].ReceivedTime is May 2005
Items[4].ReceivedTime is October 2005
Items[5].ReceivedTime is June 2005

I did some experiments and the following seems to explain how
out-of-order MailItems could happen: assuming I have n items in
my Inbox, if I delete a piece of mail, go to the Trash folder, and
move the just-deleted mail back to the Inbox, the index of the mail
is not its original index, but n. Which makes perfect sense.
The piece of mail was removed from the Items queue, and then
added to the end of the queue, hence its index is the top (n).
All cool with me.

BUT

I need some way to iterate through the emails, stopping when
I reach some date threshold. The reason is, the clients have
HUGE inboxes, like 15,000 emails, and I want to only look at
the ones within the last month. Unfortunately, CreationTime,
LastModificationTime and DeferredDeliveryTime all generally
have the same value as ReceivedTime, which means I can't
just walk my way through Items until I reach something earlier
than last month and then stop (because Items is out-of-order,
hence something from this month might be after that).

Any ideas for how to walk through the Items array, finding just
the items from this month, without searching through all
15,000 emails?

Thanks,
Harold
 
S

Sue Mosher [MVP-Outlook]

Have you considered using either Items.Sort or Items.Restrict?

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
N

Nicholas Paldino [.NET/C# MVP]

Harold,

Have you checked the Sort property on the Items collection? It will
allow you to sort the list by a certain field.

Also, you might want to consider using the Find and FindNext methods on
the Items collection, as they will iterate from the current item through the
list, and find the items that correspond to the criteria that you specify.

I mention the Find and the FindNext methods because if you do a sort
operation, you are going to have to iterate through the list somehow in
order to sort the items in the first place. If you are going to do that,
then iterate through some number of items to determine which ones are
applicable, you might as well just iterate through the whole list once with
Find and FindNext.

Hope this helps.
 

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