ItemAdd Multiple Folders

  • Thread starter Thread starter Christie Sorenson
  • Start date Start date
C

Christie Sorenson

Hello,
I am using C# to develop an outlook com addin. We have a
folder called Clients and under it about 75 client
folders. Under each of them are 1-4 project folders. I
need to capture whenever a mail item is added to any of
these folders.

Right now, I have a list as a member of my connect class.
At Startup, I add each folder to the list and set the
ItemAdd event to be triggered. This takes about 30
seconds and sometimes fails because it takes so long. If
I only hook into the clients, it takes about 10 seconds
but never fails.

I was wondering if there was a quicker, better way to do
this?
Thank you,
Christie
 
The standard way to do what you want is to set up a collection of Items
collections, which use one class module per Items collection to encapsulate
the Items collection and handle events for it such as ItemAdd. That's a VB
type description but it's the only way to do what you want.
 
Hmm. I must be doing something wrong. I've never created
a wrapper class before, so I know I'm missing something.
Here is what I have now:

1. I have a wrapper class called ItemWrapper.
2. This is my constructor:
public ItemWrapper(Microsoft.Office.Interop.Outlook.Items
item)
{
this.item = item;
((ItemsEvents_Event)this.item).ItemAdd += new
Microsoft.Office.Interop.Outlook.ItemsEvents_ItemAddEventHa
ndler(Item_Add);
}

3. I have a collection of ItemWrappers called folderitems.

4. In OnStartupComplete, I loop through the folders and
for each folder do this:

Items newfolder = clientfolder.Folders.Items;
ItemWrapper wrap = new ItemWrapper(newfolder);
folderitems.Add(wrap);


Doing it this way still takes the same amount of time. It
works, it's just very very slow.

Any ideas on what I'm doing wrong?

Thanks again,
Christie
 
I don't use .NET for Outlook, too many problems and too slow. So I can't
help with that. I have a VB 6 sample of an Inspector wrapper posted at
http://www.slovaktech.com/code_samples.htm#InspectorWrapper which could be
used as a model for an Items collection wrapper, it would be similar.
However going through the COM interop wrapper would slow things down
considerably.
 
Thanks for all your help. I have realized that it is just
the actual looping through all of the folders to add them
to the collection wrapper that is taking so long. I guess
there is no way around that :(
Thanks again,
Christie

-----Original Message-----
I don't use .NET for Outlook, too many problems and too slow. So I can't
help with that. I have a VB 6 sample of an Inspector wrapper posted at
http://www.slovaktech.com/code_samples.htm#InspectorWrappe r which could be
used as a model for an Items collection wrapper, it would be similar.
However going through the COM interop wrapper would slow things down
considerably.




Hmm. I must be doing something wrong. I've never created
a wrapper class before, so I know I'm missing something.
Here is what I have now:

1. I have a wrapper class called ItemWrapper.
2. This is my constructor:
public ItemWrapper (Microsoft.Office.Interop.Outlook.Items
item)
{
this.item = item;
((ItemsEvents_Event)this.item).ItemAdd += new
Microsoft.Office.Interop.Outlook.ItemsEvents_ItemAddEventHa
ndler(Item_Add);
}

3. I have a collection of ItemWrappers called folderitems.

4. In OnStartupComplete, I loop through the folders and
for each folder do this:

Items newfolder = clientfolder.Folders.Items;
ItemWrapper wrap = new ItemWrapper(newfolder);
folderitems.Add(wrap);


Doing it this way still takes the same amount of time. It
works, it's just very very slow.

Any ideas on what I'm doing wrong?

Thanks again,
Christie



.
 
If there are a lot of folders it can take a while.

Native COM code would be faster than using the interop and NET code.

Using CDO 1.21 to iterate the folders would be an order of magnitude faster
than using the Outlook object model. Using Redemption in that sort of thing
might be a bit faster than Outlook code but slower than CDO. It might also
be slower than Outlook, it is for some things, particularly if you have to
use COM repeatedly to create Redemption objects.

Personally, I always use CDO for iterations of large collections where I
can, due to the better memory handling (memory leaks) and far faster
operation. Of course CDO is an optional installation, so you can't always
count on it being installed.
 
Back
Top