A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Add-ins for Outlook
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Find Related Messages in Outlook 2003 with VSTO 2005 C#



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old April 15th 08, 07:11 AM posted to microsoft.public.outlook.program_addins
PGS123
external usenet poster
 
Posts: 5
Default Find Related Messages in Outlook 2003 with VSTO 2005 C#

Hi,

I have a sample code here which simply looks for the same email subject and
returns the total of number messages located in a folder. But this code took
noticeably longer time to execute compare to the good old Outlook's "Find All
/ Related Messages" feature. This Outlook's feature returns a list in an
instant without delay while this sample code took at least 2 or more seconds
to return just a number.

==================== begin ==================
private int FindEmailsWithSameSubject(string EmailSubject)
{
int MessageFound = 0;

// The following two variables are declared
// private Outlook.Application App;
// private Outlook.Explorer CurrentExplorer;
// and defined globally in the main class:
// App = new Outlook.Application();
// CurrentExplorer = App.ActiveExplorer();

Outlook.MAPIFolder SelectedFolder = CurrentExplorer.CurrentFolder;

foreach (Object SelectedObject in SelectedFolder.Items)
{
// Only work on messages which are email items.
if (SelectedObject is Outlook.MailItem)
{
Outlook.MailItem MailItem = SelectedObject as Outlook.MailItem;
if (EmailSubject == MailItem.Subject)
{
++MessageFound;
}
}
}
return MessageFound;
}
==================== end ==================

This code is executed on an inbox with just 190 messages. Questions:

1) Why this code take a longer time to run?
2) Is there a better way to find all related messages?

Thanks a lot.
Robin

Ads
  #2  
Old April 15th 08, 02:20 PM posted to microsoft.public.outlook.program_addins
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default Find Related Messages in Outlook 2003 with VSTO 2005 C#

It would be much faster to use a filter or restriction on the Items
collection of that folder using Subject as the filter condition. Review the
help in the Outlook VBA Object Browser for Items.Restrict, it shows how to
construct a restriction on various Outlook properties. The same type filter
also would apply if you use the Find methods. Which you use depends on how
many hits you expect.

--
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


"PGS123" wrote in message
...
Hi,

I have a sample code here which simply looks for the same email subject
and
returns the total of number messages located in a folder. But this code
took
noticeably longer time to execute compare to the good old Outlook's "Find
All
/ Related Messages" feature. This Outlook's feature returns a list in an
instant without delay while this sample code took at least 2 or more
seconds
to return just a number.

==================== begin ==================
private int FindEmailsWithSameSubject(string EmailSubject)
{
int MessageFound = 0;

// The following two variables are declared
// private Outlook.Application App;
// private Outlook.Explorer CurrentExplorer;
// and defined globally in the main class:
// App = new Outlook.Application();
// CurrentExplorer = App.ActiveExplorer();

Outlook.MAPIFolder SelectedFolder = CurrentExplorer.CurrentFolder;

foreach (Object SelectedObject in SelectedFolder.Items)
{
// Only work on messages which are email items.
if (SelectedObject is Outlook.MailItem)
{
Outlook.MailItem MailItem = SelectedObject as Outlook.MailItem;
if (EmailSubject == MailItem.Subject)
{
++MessageFound;
}
}
}
return MessageFound;
}
==================== end ==================

This code is executed on an inbox with just 190 messages. Questions:

1) Why this code take a longer time to run?
2) Is there a better way to find all related messages?

Thanks a lot.
Robin


  #3  
Old April 16th 08, 01:06 AM posted to microsoft.public.outlook.program_addins
PGS123
external usenet poster
 
Posts: 5
Default Find Related Messages in Outlook 2003 with VSTO 2005 C#

Hi Ken,

Got it. Thanks very much for your tips.

Robin

"Ken Slovak - [MVP - Outlook]" wrote:

It would be much faster to use a filter or restriction on the Items
collection of that folder using Subject as the filter condition. Review the
help in the Outlook VBA Object Browser for Items.Restrict, it shows how to
construct a restriction on various Outlook properties. The same type filter
also would apply if you use the Find methods. Which you use depends on how
many hits you expect.

--
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


"PGS123" wrote in message
...
Hi,

I have a sample code here which simply looks for the same email subject
and
returns the total of number messages located in a folder. But this code
took
noticeably longer time to execute compare to the good old Outlook's "Find
All
/ Related Messages" feature. This Outlook's feature returns a list in an
instant without delay while this sample code took at least 2 or more
seconds
to return just a number.

==================== begin ==================
private int FindEmailsWithSameSubject(string EmailSubject)
{
int MessageFound = 0;

// The following two variables are declared
// private Outlook.Application App;
// private Outlook.Explorer CurrentExplorer;
// and defined globally in the main class:
// App = new Outlook.Application();
// CurrentExplorer = App.ActiveExplorer();

Outlook.MAPIFolder SelectedFolder = CurrentExplorer.CurrentFolder;

foreach (Object SelectedObject in SelectedFolder.Items)
{
// Only work on messages which are email items.
if (SelectedObject is Outlook.MailItem)
{
Outlook.MailItem MailItem = SelectedObject as Outlook.MailItem;
if (EmailSubject == MailItem.Subject)
{
++MessageFound;
}
}
}
return MessageFound;
}
==================== end ==================

This code is executed on an inbox with just 190 messages. Questions:

1) Why this code take a longer time to run?
2) Is there a better way to find all related messages?

Thanks a lot.
Robin



 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
vsto 2005 se/outlook 2003 add-in doesn't load Rajesh Deshpande Add-ins for Outlook 3 May 3rd 07 10:33 PM
Doubt whether I can develop Outlook plugin for Outlook 2003 and using VSTO 2005 SE PShah Add-ins for Outlook 5 February 8th 07 09:54 PM
VSTO 2005 SE add-in for Outlook 2003 & Outlook 2007? Michael Add-ins for Outlook 3 January 23rd 07 08:16 PM
VSTO 2005 SE is final, free (w/VS Pro 2005) and supports OL2003 *s Tadwick Outlook and VBA 5 November 15th 06 06:54 PM
Outlook --Find All Related Messages Kathryn F. California Outlook - Installation 0 March 27th 06 03:48 AM


All times are GMT +1. The time now is 05:58 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.