• Subject: Re: Attaching events to the folder in Outlook 2007
  • Author: Sunil
  • Date: 02 Sep 2008
  • References: 1 2 3 4
Thanks Ken. I will put more thought on this approach. Mean time, the item
add event on the folder gets fired even single item is added in the folder.
I am able to retain the event association to the folder by attaching the
event to the folder in the Item send of the Addin.

Thanks,
Sunil

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

> The ItemAdd event will fire unless 16 or more items are added to the folder
> at once. That's a MAPI limitation where only a folder change event fires
> when 16 or more items are added/changed/deleted.
>
> If your processing will take a long time I'd probably be using a background
> worker thread to do the processing, but I'd be very careful about that. The
> Outlook object model should never be accessed except on the main thread of
> your application and not from any other or background threads. The only safe
> way to do that is to marshal your calls back to the main thread, otherwise
> Outlook has a tendency to crash or hang. So you gather all the data you need
> from the object model into a structure of some sort and use that structure
> in the background thread if possible. Otherwise you have to handle
> everything in the main thread.
>
> --
> 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
>
>
> "Sunil" <Sunil@discussions.microsoft.com> wrote in message
> news:3B3BC9F4-CCBC-4806-B9A9-23CB5BC0FED7@microsoft.com...
> > Thanks Ken for your suggestions. The code in the addin is given below. I
> > have
> > added the event to the folder in InternalStartup().
> >
> >
> >
> >
> >
> > public partial class ThisAddIn
> > {
> >
> > Outlook.MAPIFolder MyFolder = null;
> >
> >
> > private Outlook.MAPIFolder CreateMyFolder()
> > {
> > Outlook.MAPIFolder MyInboxFolder =
> > this.Application.Session.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);
> > bool IsFolderExist = false;
> > foreach (Outlook.MAPIFolder folder in MyInboxFolder.Folders)
> > {
> > if (folder.Name.Equals("MyFolder"))
> > {
> > MyFolder = folder;
> > IsFolderExist = true;
> > break;
> > }
> > }
> > if (MyFolder == null || IsFolderExist == false)
> > {
> > MyFolder = MyInboxFolder.Folders.Add("MyFolder",
> > Outlook.OlDefaultFolders.olFolderInbox);
> > MyFolder.WebViewOn = false;
> > MyFolder.ShowAsOutlookAB = false;
> > MyFolder.InAppFolderSyncObject = false;
> > }
> >
> > MyFolder.Items.ItemAdd += new
> > Microsoft.Office.Interop.Outlook.ItemsEvents_ItemAddEventHandler(Items_ItemAdd);
> > return MyFolder;
> > }
> >
> >
> > private void InternalStartup()
> > {
> > this.Startup += new System.EventHandler(ThisAddIn_Startup);
> > this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
> >
> > CreateMyFolder()
> > }
> > }
> >
> >
> > The task I want to achieve is I have list of recipients whom I have to
> > process. The Processing part is going to take very long time. Therefore
> > what
> > I have decided is once the user clicks on the Send button, the mail will
> > be
> > saved in another custom folder. Once the mail is pushed into the custom
> > folder, I will be performing the processing.
> >
> > In this case the event attachment to the folder and the Recipient
> > processing
> > resides in the Addin. As per my logic, the the processing part will be
> > added
> > in the Sent Event of my Addin. First time when the user clicks on the send
> > button, from SentItem event I am saving that message in the custom folder
> > based on the origin of the mail message. When the mail is sent from the
> > custom folder, I will be performing the processing logic.
> >
> > As per my understanding the the event attached to the custom folder does
> > not
> > get fired after some time.
> >
> > Please let me know I can go about making sure that the event gets fired
> > all
> > the time whenever the item is inserted into that custom folder.
> >
> > Your guidence will be highly appreciated.
> >
> > Thanks,
> > Sunil
> >
> >
> >
> >
> > "Ken Slovak - [MVP - Outlook]" wrote:
> >
> >> You do realize that the InAppFolderSyncObject property only sets whether
> >> the
> >> folder should be synched for the "Application Folders" SyncObject only,
> >> and
> >> creates that SyncObject if it doesn't exist already? So if the folder is
> >> set
> >> to be synched with the "All Accounts" group for example that setting
> >> won't
> >> have any effect.
> >>
> >> It's most likely a matter of scope. Whatever object you are using for the
> >> folder that you're attaching the events to must be declared at a scope
> >> level
> >> that is constant for as long as you want the events to fire. Otherwise
> >> the
> >> object and its events will go out of scope and eventually get garbage
> >> collected. For something like that I'd usually declare the folder object
> >> at
> >> a class level so it stays alive as long as the class stays alive.
> >>
> >> --
> >> Ken Slovak
> >> [MVP - Outlook]
> >> http://www.slovaktech.com
>
>
28 Aug 2008Attaching events to the folder in Outlook 2007.Sunil
28 Aug 2008|- RE: Attaching events to the folder in Outlook 2007.Sunil
28 Aug 2008\ Re: Attaching events to the folder in Outlook 2007.Ken Slovak - [MVP - O...
01 Sep 2008   \ Re: Attaching events to the folder in Outlook 2007.Sunil
01 Sep 2008      \ Re: Attaching events to the folder in Outlook 2007.Ken Slovak - [MVP - O...
02 Sep 2008         \ Re: Attaching events to the folder in Outlook 2007.Sunil
All times are in (US) Eastern Daylight Time (GMT -4:00)