Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Outlook / Programming Add-Ins / September 2007

Tip: Looking for answers? Try searching our database.

Optimize iteration through mailitems

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
jorgen.slettahjell@gmail.com - 25 Sep 2007 09:38 GMT
I'm currently experiencing very bad performance while iterating
through the mailitems in a folder. I have to do this to check some
values in a couple of my custom properties every time a user is
switching folders.
I have read a lot about the Items.SetColumns() method, but can't seem
to get it to work with my custom properties.
This method is supposed to cache the properties you want to use, so
Outlook doesn't need to open every property of every mailitem you
visit.

Examples of what I have tried:
items.SetColumns("Storage"); // where Storage is my custom property
items.SetColumns("http://schemas.microsoft/mapi/string/
{00020329-0000-0000-C000-000000000046}/Storage");
items.SetColumns("http://schemas.microsoft/mapi/id/{00020329-0000-0000-
C000-000000000046}/0x8020001E"); // 8020 is according to outlook spy
the tag for this property and 001E is the tag for STRING8
items.SetColumns("http://schemas.microsoft/mapi/proptag/0x8020001E");

In addition, I have tried every possible combination of the above,
with no luck...

Any suggestions!??

The method does work with EntryID, Subject and fields like that, but
not with my custom ones.. :(

Any help would be appreciated
Ken Slovak - [MVP - Outlook] - 25 Sep 2007 15:16 GMT
According to the Object Browser Help on SetColumns using EntryID will cause
an error.

If your user properties have been added to the folder and not just the items
you can use a filter or restriction if you're looking for specific values in
the user properties (for example a user property that has the value True).

Are you just using the Outlook object model or are you also using an
alternate API such as Redemption? If you're using Redemption or Outlook 2007
you could set up a request for a MAPITable object that just returns the
columns represented by your user properties plus anything else you might
need such as EntryID, that would be extremely fast, probably about an order
of magnitude faster than any method using the Outlook object model. You
could also filter or restrict that returned table object for even faster
performance.

Signature

Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm

> I'm currently experiencing very bad performance while iterating
> through the mailitems in a folder. I have to do this to check some
[quoted text clipped - 24 lines]
>
> Any help would be appreciated
jorgen.slettahjell@gmail.com - 26 Sep 2007 13:36 GMT
Thank you very much for your response Ken :)

Yes, I am using Redemption, and I have tried to replicate the code on
this page < http://www.dimastr.com/redemption/mapitable.htm#tablefiltering
> to suit my c# project.
Now, what I need to do is to understand what I am supposed to do with
the result of this. I have investigated the "rows" variable, which
turns out to be a System.Array object including data from my
mailitems.

Here is my code:

int [] columns = new int[3];
Outlook.Items items = selectedFolder.Items;
Redemption.SafeMailItem safeMail = new Redemption.SafeMailItem();
safeMail.Item = items[1];

int cmTag = safeMail.GetIDsFromNames("{00020329-0000-0000-
C000-000000000046}", "Storage");
cmTag = cmTag + 0x001E;
columns[0] = cmTag;

cmTag = safeMail.GetIDsFromNames("{00020329-0000-0000-
C000-000000000046}", "RID");
cmTag = cmTag + 0x001E;
columns[1] = cmTag;

cmTag = safeMail.GetIDsFromNames("{00020329-0000-0000-
C000-000000000046}", "Account");
cmTag = cmTag + 0x001E;
columns[2] = cmTag;

Redemption.MAPITable mapiTable = new Redemption.MAPITable();
mapiTable.Item = items;
mapiTable.Columns = columns;
mapiTable.GoToFirst();
object rows = mapiTable.GetRows(mapiTable.RowCount);

Now, my next step is to decrypt the rows variable. I guess I have to
cast it to System.Array and try to get hold of the data in it.
Then I will have to iterate through the data, and pick up the
mailitems that fit my criteria and then do whatever I need to do with
them.
Can you verify to me that this is the right approach?
If you have a tip on how to include EntryID of messages to the columns
filter and how to get hold of the message by using this EntryID, I'd
appreciate it very much :)

J?rgen

On 25 Sep, 16:16, "Ken Slovak - [MVP - Outlook]" <kenslo...@mvps.org>
wrote:
> According to the Object Browser Help on SetColumns using EntryID will cause
> an error.
[quoted text clipped - 50 lines]
>
> > Any help would be appreciated
Ken Slovak - [MVP - Outlook] - 26 Sep 2007 14:42 GMT
The approach is correct but I'd probably loop the table and not use GetRows
unless I was positive I was getting a limited number of rows back. I'd
either use GetRows(20) or GetRow, since MAPI has limitations on how much
data it can return in one pass.

EntryID is really a PT_BINARY property, so when you get it back you will
need to use HrArrayToString to convert it to a string value. If it's
possible that Exchange is involved you also have to ask for both the
short-term and long-term id's and check for an empty value on long-term
before checking for short-term. If you only have a PST file to query then
you can just use EntryID (PR_ENTRYID = 0x0FFF0102).

const int PR_ENTRYID = 0x0FFF0102;
const int PR_LONGTERM_ENTRYID_FROM_TABLE = 0x66700102;

Probably just for clarity I'd also Or the property type with the tag instead
of using an addition operator, but that's more a matter of style.

After you have the EntryID for an item retrieving the item is simple using
the NameSpace.GetItemFromID() method.

Signature

Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm

Thank you very much for your response Ken :)

Yes, I am using Redemption, and I have tried to replicate the code on
this page < http://www.dimastr.com/redemption/mapitable.htm#tablefiltering
> to suit my c# project.
Now, what I need to do is to understand what I am supposed to do with
the result of this. I have investigated the "rows" variable, which
turns out to be a System.Array object including data from my
mailitems.

Here is my code:

int [] columns = new int[3];
Outlook.Items items = selectedFolder.Items;
Redemption.SafeMailItem safeMail = new Redemption.SafeMailItem();
safeMail.Item = items[1];

int cmTag = safeMail.GetIDsFromNames("{00020329-0000-0000-
C000-000000000046}", "Storage");
cmTag = cmTag + 0x001E;
columns[0] = cmTag;

cmTag = safeMail.GetIDsFromNames("{00020329-0000-0000-
C000-000000000046}", "RID");
cmTag = cmTag + 0x001E;
columns[1] = cmTag;

cmTag = safeMail.GetIDsFromNames("{00020329-0000-0000-
C000-000000000046}", "Account");
cmTag = cmTag + 0x001E;
columns[2] = cmTag;

Redemption.MAPITable mapiTable = new Redemption.MAPITable();
mapiTable.Item = items;
mapiTable.Columns = columns;
mapiTable.GoToFirst();
object rows = mapiTable.GetRows(mapiTable.RowCount);

Now, my next step is to decrypt the rows variable. I guess I have to
cast it to System.Array and try to get hold of the data in it.
Then I will have to iterate through the data, and pick up the
mailitems that fit my criteria and then do whatever I need to do with
them.
Can you verify to me that this is the right approach?
If you have a tip on how to include EntryID of messages to the columns
filter and how to get hold of the message by using this EntryID, I'd
appreciate it very much :)

Jørgen
jorgen.slettahjell@gmail.com - 26 Sep 2007 13:36 GMT
Thank you very much for your response Ken :)

Yes, I am using Redemption, and I have tried to replicate the code on
this page < http://www.dimastr.com/redemption/mapitable.htm#tablefiltering
> to suit my c# project.
Now, what I need to do is to understand what I am supposed to do with
the result of this. I have investigated the "rows" variable, which
turns out to be a System.Array object including data from my
mailitems.

Here is my code:

int [] columns = new int[3];
Outlook.Items items = selectedFolder.Items;
Redemption.SafeMailItem safeMail = new Redemption.SafeMailItem();
safeMail.Item = items[1];

int cmTag = safeMail.GetIDsFromNames("{00020329-0000-0000-
C000-000000000046}", "Storage");
cmTag = cmTag + 0x001E;
columns[0] = cmTag;

cmTag = safeMail.GetIDsFromNames("{00020329-0000-0000-
C000-000000000046}", "RID");
cmTag = cmTag + 0x001E;
columns[1] = cmTag;

cmTag = safeMail.GetIDsFromNames("{00020329-0000-0000-
C000-000000000046}", "Account");
cmTag = cmTag + 0x001E;
columns[2] = cmTag;

Redemption.MAPITable mapiTable = new Redemption.MAPITable();
mapiTable.Item = items;
mapiTable.Columns = columns;
mapiTable.GoToFirst();
object rows = mapiTable.GetRows(mapiTable.RowCount);

Now, my next step is to decrypt the rows variable. I guess I have to
cast it to System.Array and try to get hold of the data in it.
Then I will have to iterate through the data, and pick up the
mailitems that fit my criteria and then do whatever I need to do with
them.
Can you verify to me that this is the right approach?
If you have a tip on how to include EntryID of messages to the columns
filter and how to get hold of the message by using this EntryID, I'd
appreciate it very much :)

J?rgen

On 25 Sep, 16:16, "Ken Slovak - [MVP - Outlook]" <kenslo...@mvps.org>
wrote:
> According to the Object Browser Help on SetColumns using EntryID will cause
> an error.
[quoted text clipped - 50 lines]
>
> > Any help would be appreciated
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2010 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.