none
Catch new item in sync issues folder RRS feed

  • Question

  • Hi,

    could you help me to subscribe to appropriate event to catching every new item in Sync Issues folder ?

    Thank you in advance,

    Tuesday, March 20, 2012 5:36 PM

Answers

  • Something like this would handle various numbers of subfolders under SyncIssues. It uses a handler class to handle each folder instance's Items.ItemAdd() event. It's just stub code, you need to add your own logic and exception handling.
     

    using Outlook = Microsoft.Office.Interop.Outlook;

    using Office = Microsoft.Office.Core;

    using System.Runtime.InteropServices;

    namespace OutlookAddIn1

    {

    public partial class ThisAddIn

    {

    private System.Collections.Generic.List<FolderHandler> _list = null;

    private void ThisAddIn_Startup(object sender, System.EventArgs e)

    {

    Outlook.NameSpace ns = this.Application.GetNamespace("MAPI");

    Outlook.Folder fol = ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderSyncIssues) as Outlook.Folder;

    GetFolderToAdd(fol);

    Marshal.ReleaseComObject(fol);

    fol = null;

    Marshal.ReleaseComObject(ns);

    ns = null;

    }

    private void GetFolderToAdd(Outlook.Folder folder)

    {

    AddFolder(folder);

    Outlook.Folders fols = folder.Folders;

    if (fols.Count > 0)

    {

    Outlook.Folder fol = null;

    for (int i = 1; i <= fols.Count; i++)

    {

    fol = fols[i] as Outlook.Folder;

    GetFolderToAdd(fol);

    Marshal.ReleaseComObject(fol);

    fol = null;

    }

    }

    Marshal.ReleaseComObject(fols);

    fols = null;

    }

    private void AddFolder(Outlook.Folder folder)

    {

    _list.Add(new FolderHandler(folder));

    }

    private void ThisAddIn_Shutdown(object sender, System.EventArgs e)

    {

    }

    // handler class:

    using Outlook = Microsoft.Office.Interop.Outlook;

    using System.Runtime.InteropServices;

    namespace OutlookAddIn1

    {

    public class FolderHandler

    {

    private Outlook.Folder _folder = null;

    private Outlook.Items _items = null;

    public FolderHandler(Outlook.Folder folder)

    {

    _folder = folder;

    _items = _folder.Items;

    _items.ItemAdd += new Outlook.ItemsEvents_ItemAddEventHandler(_items_ItemAdd);

    }

    public void Kill()

    {

    _items.ItemAdd -= new Outlook.ItemsEvents_ItemAddEventHandler(_items_ItemAdd);

    Marshal.ReleaseComObject(_items);

    _items = null;

    Marshal.ReleaseComObject(_folder);

    _folder = null;

    GC.Collect();

    }

    private void _items_ItemAdd(object Item)

    {

    throw new NotImplementedException();

    }

    }

    }

     


    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "al.kozlov" <=?utf-8?B?YWwua296bG92?=> wrote in message news:7c0b6b27-d51f-4418-934c-4ffb8615148b...

    Hi, Ken !

    Office 2010 , VSTO, C#.

    I need a folder and any subfolders too.


    Ken Slovak MVP - Outlook
    • Marked as answer by al.kozlov Wednesday, March 21, 2012 5:23 PM
    Tuesday, March 20, 2012 10:38 PM

All replies

  • What language and what version of Outlook?
     
    Is this a VSTO addin?
     
    Do you want only that folder's ItemAdd () event for its Items collection, or for that folder and any subfolders?

    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "al.kozlov" <=?utf-8?B?YWwua296bG92?=> wrote in message news:28d91a1a-34ec-476d-8f49-0d26aff8a376...

    Hi,

    could you help me to subscribe to appropriate event to catching every new item in Sync Issues folder ?

    Thank you in advance,


    Ken Slovak MVP - Outlook
    Tuesday, March 20, 2012 6:25 PM
  • Hi, Ken !

    Office 2010 , VSTO, C#.

    I need a folder and any subfolders too.

    Tuesday, March 20, 2012 6:42 PM
  • Something like this would handle various numbers of subfolders under SyncIssues. It uses a handler class to handle each folder instance's Items.ItemAdd() event. It's just stub code, you need to add your own logic and exception handling.
     

    using Outlook = Microsoft.Office.Interop.Outlook;

    using Office = Microsoft.Office.Core;

    using System.Runtime.InteropServices;

    namespace OutlookAddIn1

    {

    public partial class ThisAddIn

    {

    private System.Collections.Generic.List<FolderHandler> _list = null;

    private void ThisAddIn_Startup(object sender, System.EventArgs e)

    {

    Outlook.NameSpace ns = this.Application.GetNamespace("MAPI");

    Outlook.Folder fol = ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderSyncIssues) as Outlook.Folder;

    GetFolderToAdd(fol);

    Marshal.ReleaseComObject(fol);

    fol = null;

    Marshal.ReleaseComObject(ns);

    ns = null;

    }

    private void GetFolderToAdd(Outlook.Folder folder)

    {

    AddFolder(folder);

    Outlook.Folders fols = folder.Folders;

    if (fols.Count > 0)

    {

    Outlook.Folder fol = null;

    for (int i = 1; i <= fols.Count; i++)

    {

    fol = fols[i] as Outlook.Folder;

    GetFolderToAdd(fol);

    Marshal.ReleaseComObject(fol);

    fol = null;

    }

    }

    Marshal.ReleaseComObject(fols);

    fols = null;

    }

    private void AddFolder(Outlook.Folder folder)

    {

    _list.Add(new FolderHandler(folder));

    }

    private void ThisAddIn_Shutdown(object sender, System.EventArgs e)

    {

    }

    // handler class:

    using Outlook = Microsoft.Office.Interop.Outlook;

    using System.Runtime.InteropServices;

    namespace OutlookAddIn1

    {

    public class FolderHandler

    {

    private Outlook.Folder _folder = null;

    private Outlook.Items _items = null;

    public FolderHandler(Outlook.Folder folder)

    {

    _folder = folder;

    _items = _folder.Items;

    _items.ItemAdd += new Outlook.ItemsEvents_ItemAddEventHandler(_items_ItemAdd);

    }

    public void Kill()

    {

    _items.ItemAdd -= new Outlook.ItemsEvents_ItemAddEventHandler(_items_ItemAdd);

    Marshal.ReleaseComObject(_items);

    _items = null;

    Marshal.ReleaseComObject(_folder);

    _folder = null;

    GC.Collect();

    }

    private void _items_ItemAdd(object Item)

    {

    throw new NotImplementedException();

    }

    }

    }

     


    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "al.kozlov" <=?utf-8?B?YWwua296bG92?=> wrote in message news:7c0b6b27-d51f-4418-934c-4ffb8615148b...

    Hi, Ken !

    Office 2010 , VSTO, C#.

    I need a folder and any subfolders too.


    Ken Slovak MVP - Outlook
    • Marked as answer by al.kozlov Wednesday, March 21, 2012 5:23 PM
    Tuesday, March 20, 2012 10:38 PM
  • Dear Ken - very nice, thank you !
    Wednesday, March 21, 2012 5:23 PM