Thanks for the reply.
Here is the entire class OutlookCalendar that I'm using. The Main Form sets
the Delegate AppointmentsModified which re-loads all the appointments for
Today (by calling the method getCalendarDataSet) and re-displays them.
I don't think that my program is modifying anything in the event or the
recurrance pattern. Am I wrong?
Thanks again for any help.
Mark
-----------------------
using System;
using System.Data;
using System.Diagnostics;
using Outlook = Microsoft.Office.Interop.Outlook;
namespace DailyPlanner
{
///
/// Summary description for OutlookCalendar.
///
public class OutlookCalendar : IDisposable
{
public delegate void AppointmentsModifiedDelegate();
public event AppointmentsModifiedDelegate AppointmentsModified;
private Outlook.Application objOutlook = null;
private Outlook.NameSpace objNamespace = null;
private Outlook.MAPIFolder objFolder = null;
Outlook.Items colCal = null;
public OutlookCalendar()
{
this.objOutlook = new Outlook.ApplicationClass();
this.objNamespace = this.objOutlook.GetNamespace("MAPI");
this.objFolder = this.objNamespace.GetDefaultFolder(Outlook.OlDefau
ltFolders.olFolderCalendar);
this.colCal = this.objFolder.Items;
this.colCal.Sort("[Start]", false);
this.colCal.IncludeRecurrences = true;
this.colCal.ItemAdd += new
Microsoft.Office.Interop.Outlook.ItemsEvents_ItemA
ddEventHandler(colCal_ItemAdd);
this.colCal.ItemChange += new
Microsoft.Office.Interop.Outlook.ItemsEvents_ItemC
hangeEventHandler(colCal_ItemChange);
this.colCal.ItemRemove += new
Microsoft.Office.Interop.Outlook.ItemsEvents_ItemR
emoveEventHandler(colCal_ItemRemove);
}
///
/// Close the Outlook application when this instance is disposed.
///
public void Dispose()
{
if (objOutlook != null)
{
this.objOutlook = null;
this.objNamespace = null;
this.objFolder = null;
this.colCal = null;
}
}
///
/// Retrieve a list of all appointments listed in the Outlook calendar.
///
/// Calendar Items DataSet
public DataTable getCalendarDataSet(DateTime dteDate)
{
DataColumn col;
Outlook.Items thisDayItems;
DataTable rv = new DataTable("Appointment");
rv.Columns.Add("EventID");
rv.Columns.Add("Category");
col = new DataColumn("Start");
col.DataType = System.Type.GetType("System.DateTime");
rv.Columns.Add(col);
col = new DataColumn("End");
col.DataType = System.Type.GetType("System.DateTime");
rv.Columns.Add(col);
rv.Columns.Add("Subject");
col = new DataColumn("IsRepeat");
col.DataType = System.Type.GetType("System.Boolean");
rv.Columns.Add(col);
rv.Columns.Add("Repeat");
col = new DataColumn("DaysOfWeekMask");
col.DataType = System.Type.GetType("System.Int32");
rv.Columns.Add(col);
col = new DataColumn("RepeatUntil");
col.DataType = System.Type.GetType("System.DateTime");
rv.Columns.Add(col);
col = new DataColumn("Interval");
col.DataType = System.Type.GetType("System.Int32");
rv.Columns.Add(col);
rv.Columns.Add("Location");
col = new DataColumn("AllDayEvent");
col.DataType = System.Type.GetType("System.Boolean");
rv.Columns.Add(col);
rv.Columns.Add("Duration");
rv.Columns.Add("Organizer");
rv.Columns.Add("Importance");
rv.Columns.Add("Sensitivity");
rv.Columns.Add("Body");
try
{
string nowdate = dteDate.ToString("MM/dd/yyyy");
string tomorrowDate = dteDate.AddDays(1).ToString("MM/dd/yyyy");
string query = "[Start] >= '" + nowdate + " 00:00 AM' and [End] <= '" +
tomorrowDate + " 00:00 AM'";
Debug.WriteLine(query);
thisDayItems = colCal.Restrict(query);
foreach(Outlook.AppointmentItem item in thisDayItems)
{
string itemID = item.EntryID;
string desc = item.Subject;
DateTime dtStart = item.Start;
DateTime dtEnd = item.End;
Outlook.RecurrencePattern recur = item.GetRecurrencePattern();
if(item.AllDayEvent)
dtEnd = dtEnd.AddSeconds(-1); //Subtract one second from the end date
if this is an all day event
rv.Rows.Add(new object[]
{
itemID,
item.Categories,
dtStart,
dtEnd,
item.Subject,
item.IsRecurring,
recur.RecurrenceType,
recur.DayOfWeekMask,
recur.PatternEndDate,
recur.Interval,
item.Location,
item.AllDayEvent,
item.Duration,
item.Organizer,
item.Importance,
item.Sensitivity,
item.Body
});
}
Debug.WriteLine(rv.Rows.Count + " Appointments exported.");
}
catch (System.Exception e)
{
Console.WriteLine(e);
}
return rv;
}
public void ShowEntry(string entryID)
{
objFolder = objNamespace.GetDefaultFolder(Outlook.OlDefaultFol
ders.olFolderCalendar);
Outlook.AppointmentItem item =
(Outlook.AppointmentItem)objNamespace.GetItemFromI D(entryID,
objFolder.StoreID);
if(item != null)
item.Display(false);
}
private void colCal_ItemAdd(object Item)
{
if(this.AppointmentsModified != null)
this.AppointmentsModified();
}
private void colCal_ItemChange(object Item)
{
if(this.AppointmentsModified != null)
this.AppointmentsModified();
}
private void colCal_ItemRemove()
{
if(this.AppointmentsModified != null)
this.AppointmentsModified();
}
}
}