A
Atul Sureka
Hi
I am using the following code to track FolderRemove event of task Folder and its SubFolders.
using System;
using System.Collections;
using Outlook = Microsoft.Office.Interop.Outlook;
class Temp
{
public static void Main()
{
MyClass obj = new MyClass();
Console.WriteLine("Listening ...............");
Console.ReadLine();
}
}
class MyClass
{
Outlook.Application app;
Outlook.NameSpace nSpace;
// Stores the "Task" Folder
private Outlook.MAPIFolder mapiFolder;
// ArrayList to store the subFolders
private ArrayList subFolderList;
public MyClass()
{
try
{
app = new Microsoft.Office.Interop.Outlook.Application();
nSpace = app.GetNamespace("MAPI");
mapiFolder = nSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderTasks);
subFolderList = new ArrayList();
GetSubFolderList(mapiFolder);
itemsList = new ArrayList();
}
catch (Exception Ex)
{
Console.WriteLine(Ex.Message);
}
}
// Recursive function to attach events with folders and its subfolders
void GetSubFolderList(Outlook.MAPIFolder folder)
{
Outlook.Folders fol = folder.Folders;
subFolderList.Add(fol);
// Attach event handlers
fol.FolderRemove += new Outlook.FoldersEvents_FolderRemoveEventHandler(fol_FolderRemove);
fol.FolderChange += new Outlook.FoldersEvents_FolderChangeEventHandler(fol_FolderChange);
foreach (Outlook.MAPIFolder f in folder.Folders)
{
// Recursivly call for the subfolders
GetSubFolderList(f);
}
}
void fol_FolderChange(Microsoft.Office.Interop.Outlook.MAPIFolder Folder)
{
Console.WriteLine("Folder has been changed....");
}
void fol_FolderRemove()
{
Console.WriteLine("Folder has been removed....");
}
}
Lets My Outlook has four folders with following hierarchy.
Task // Main Task Folder of Outlook
F1 // SubFolder of Task Folder
F2 // SubFolder of Task Folder
F3 // SubFolder of F1
When I delete F1 "FolderRemove" Event is getting fired.
However when I delete F3 "FolderChange" Event is getting fired
Why this is happening ?????
Regards
Atul Sureka
I am using the following code to track FolderRemove event of task Folder and its SubFolders.
using System;
using System.Collections;
using Outlook = Microsoft.Office.Interop.Outlook;
class Temp
{
public static void Main()
{
MyClass obj = new MyClass();
Console.WriteLine("Listening ...............");
Console.ReadLine();
}
}
class MyClass
{
Outlook.Application app;
Outlook.NameSpace nSpace;
// Stores the "Task" Folder
private Outlook.MAPIFolder mapiFolder;
// ArrayList to store the subFolders
private ArrayList subFolderList;
public MyClass()
{
try
{
app = new Microsoft.Office.Interop.Outlook.Application();
nSpace = app.GetNamespace("MAPI");
mapiFolder = nSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderTasks);
subFolderList = new ArrayList();
GetSubFolderList(mapiFolder);
itemsList = new ArrayList();
}
catch (Exception Ex)
{
Console.WriteLine(Ex.Message);
}
}
// Recursive function to attach events with folders and its subfolders
void GetSubFolderList(Outlook.MAPIFolder folder)
{
Outlook.Folders fol = folder.Folders;
subFolderList.Add(fol);
// Attach event handlers
fol.FolderRemove += new Outlook.FoldersEvents_FolderRemoveEventHandler(fol_FolderRemove);
fol.FolderChange += new Outlook.FoldersEvents_FolderChangeEventHandler(fol_FolderChange);
foreach (Outlook.MAPIFolder f in folder.Folders)
{
// Recursivly call for the subfolders
GetSubFolderList(f);
}
}
void fol_FolderChange(Microsoft.Office.Interop.Outlook.MAPIFolder Folder)
{
Console.WriteLine("Folder has been changed....");
}
void fol_FolderRemove()
{
Console.WriteLine("Folder has been removed....");
}
}
Lets My Outlook has four folders with following hierarchy.
Task // Main Task Folder of Outlook
F1 // SubFolder of Task Folder
F2 // SubFolder of Task Folder
F3 // SubFolder of F1
When I delete F1 "FolderRemove" Event is getting fired.
However when I delete F3 "FolderChange" Event is getting fired
Why this is happening ?????
Regards
Atul Sureka