Outlook Folder - FolderRemove Event

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
 
D

Dmitry Streblechenko

FolderChange fires on the Tasks folder because the subfolder (F1) is
modified - one of its own subfodlers is deleted (F3).

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

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
 
A

Atul Sureka

When I delete F3 - it means that I have modified F1, so FolderChange event
of F1 is getting fire - that is fine - But I have also attached handler for
FolderRemove event of F3, So If I delete F3 then FolderRemove event for this
folder should also fire. unfortunately this is not firing :( ??????


Atul Sureka
 
D

Dmitry Streblechenko

No, FoldderRemove is supposed to fire on the parent folder's
MAPIFolder.Folders collection.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top