S
Simon Francesco
I have successfully connected to and listened to the BeforeItemMove event on
a local (pst) calendar, but I cannot seem to get this event to fire for
shared calendars that I have open.
I am using Outlook 2007 connected to Exchange 2003.
All the code between the scenarios is the same except the code to resolve
and get the folder. Smippets below.
I have investiaged the more generic loss of scope of COM objects etc and
retain references to the folders to maintain their lifespan and as I said it
works in the local calendar but not shared calendars.
Could anyone shed some light on this for me?
TIA Simon
/// <summary>
/// Finds and resolves the requested folder, if found it attaches
/// to the BeforeItemMove event to listen for deletes etc
/// and adds the folder to the Application Level MonitoredFolders List
/// </summary>
/// <param name="folderToMonitor">Either the local name of the
Calendar or the
/// Recipients name in the case of an Exchange Mailbox</param>
private void StartMonitoringCalendarFolder(String folderToMonitor)
{
var folder = GetFolder(folderToMonitor);
if (folder != null)
{
//StartListening for Deletes
folder.BeforeItemMove += folder_BeforeItemMove;
//Record that we are listening, and maintain ref to COM
objects
monitoredFolders.Add(folderToMonitor, new
FolderWrapper(folder));
}
}
/// <summary>
/// Finds and returns the requested folder, allows for
/// whether Outlook is using Exchange or not.
/// Returns null if not found.
/// </summary>
/// <param name="folderToMonitor">Either the local name of the
Calendar or the
/// Recipients name in the case of an Exchange Mailbox</param>
/// <returns></returns>
private Outlook.Folder GetFolder(String folderName)
{
Outlook.Folder folder = null;
switch (this.Application.Session.ExchangeConnectionMode)
{
case
Microsoft.Office.Interop.Outlook.OlExchangeConnectionMode.olNoExchange:
var currentFolder =
(Outlook.Folder)this.Application.Session.DefaultStore.GetRootFolder();
//Walk the folder tree and look for folder name
folder = FindFolder(folderName, currentFolder);
break;
default: //all other Exchange modes, TODO: we may run into
sync issues if Outlook is offline
Outlook.Recipient recourceMailBox =
this.Application.Session.CreateRecipient(folderName);
recourceMailBox.Resolve();
if (!recourceMailBox.Resolved)
{
System.Diagnostics.Trace.WriteLine(String.Format("Folder Monitoring: Unable
to resolve folder: {0}", folderName));
return null;
}
folder =
(Outlook.Folder)this.Application.Session.GetSharedDefaultFolder(recourceMailBox, Outlook.OlDefaultFolders.olFolderCalendar);
break;
}
if (folder == null)
{
System.Diagnostics.Trace.WriteLine(String.Format("Folder
Monitoring: Unable to find folder: {0}", folderName));
}
return folder;
}
//Example call: StartMonitoringCalendarFolder("Bob Smith");
a local (pst) calendar, but I cannot seem to get this event to fire for
shared calendars that I have open.
I am using Outlook 2007 connected to Exchange 2003.
All the code between the scenarios is the same except the code to resolve
and get the folder. Smippets below.
I have investiaged the more generic loss of scope of COM objects etc and
retain references to the folders to maintain their lifespan and as I said it
works in the local calendar but not shared calendars.
Could anyone shed some light on this for me?
TIA Simon
/// <summary>
/// Finds and resolves the requested folder, if found it attaches
/// to the BeforeItemMove event to listen for deletes etc
/// and adds the folder to the Application Level MonitoredFolders List
/// </summary>
/// <param name="folderToMonitor">Either the local name of the
Calendar or the
/// Recipients name in the case of an Exchange Mailbox</param>
private void StartMonitoringCalendarFolder(String folderToMonitor)
{
var folder = GetFolder(folderToMonitor);
if (folder != null)
{
//StartListening for Deletes
folder.BeforeItemMove += folder_BeforeItemMove;
//Record that we are listening, and maintain ref to COM
objects
monitoredFolders.Add(folderToMonitor, new
FolderWrapper(folder));
}
}
/// <summary>
/// Finds and returns the requested folder, allows for
/// whether Outlook is using Exchange or not.
/// Returns null if not found.
/// </summary>
/// <param name="folderToMonitor">Either the local name of the
Calendar or the
/// Recipients name in the case of an Exchange Mailbox</param>
/// <returns></returns>
private Outlook.Folder GetFolder(String folderName)
{
Outlook.Folder folder = null;
switch (this.Application.Session.ExchangeConnectionMode)
{
case
Microsoft.Office.Interop.Outlook.OlExchangeConnectionMode.olNoExchange:
var currentFolder =
(Outlook.Folder)this.Application.Session.DefaultStore.GetRootFolder();
//Walk the folder tree and look for folder name
folder = FindFolder(folderName, currentFolder);
break;
default: //all other Exchange modes, TODO: we may run into
sync issues if Outlook is offline
Outlook.Recipient recourceMailBox =
this.Application.Session.CreateRecipient(folderName);
recourceMailBox.Resolve();
if (!recourceMailBox.Resolved)
{
System.Diagnostics.Trace.WriteLine(String.Format("Folder Monitoring: Unable
to resolve folder: {0}", folderName));
return null;
}
folder =
(Outlook.Folder)this.Application.Session.GetSharedDefaultFolder(recourceMailBox, Outlook.OlDefaultFolders.olFolderCalendar);
break;
}
if (folder == null)
{
System.Diagnostics.Trace.WriteLine(String.Format("Folder
Monitoring: Unable to find folder: {0}", folderName));
}
return folder;
}
//Example call: StartMonitoringCalendarFolder("Bob Smith");