Outlook Banter

Outlook Banter (http://www.outlookbanter.com/)
-   Add-ins for Outlook (http://www.outlookbanter.com/add-ins-outlook/)
-   -   ItemChange event is modifying my Calendar Events (http://www.outlookbanter.com/add-ins-outlook/31475-itemchange-event-modifying-my-calendar.html)

mark October 30th 06 05:06 PM

ItemChange event is modifying my Calendar Events
 
I've got what I think is a wierd problem here. I am trying to display a "Daily Planner" on my desktop that shows all my appointments for the day. This little program works great with one annoying problem. If the application is running and I open a Calendar Event within Outlook itself...I don't change anything but hit the Save & Close button on the Event. When the Event is saved, it now has a Weekly Recurrance set on the event. All Events that are modified will now have the weekly recurrance set if my little application is running. If I close my "Daily Planner", this symptom goes away completely.

Any and all help would be greatly appreciated.

Mark


EggHeadCafe.com - .NET Developer Portal of Choice
http://www.eggheadcafe.com

Ken Slovak - [MVP - Outlook] October 31st 06 03:06 PM

ItemChange event is modifying my Calendar Events
 
Obviously your program is setting a recurrence pattern or is accessing
RecurrencePattern without checking first for IsRecurring. Without seeing
what your code is doing there's no way to say anything more.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


Mark wrote in message . ..
I've got what I think is a wierd problem here. I am trying to display a
"Daily Planner" on my desktop that shows all my appointments for the day.
This little program works great with one annoying problem. If the
application is running and I open a Calendar Event within Outlook
itself...I don't change anything but hit the Save & Close button on the
Event. When the Event is saved, it now has a Weekly Recurrance set on the
event. All Events that are modified will now have the weekly recurrance
set if my little application is running. If I close my "Daily Planner",
this symptom goes away completely.

Any and all help would be greatly appreciated.

Mark


EggHeadCafe.com - .NET Developer Portal of Choice
http://www.eggheadcafe.com



Mark November 6th 06 08:20 PM

ItemChange event is modifying my Calendar Events
 
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();
}
}
}


Ken Slovak - [MVP - Outlook] November 6th 06 08:54 PM

ItemChange event is modifying my Calendar Events
 
As I mentioned, you need to check IsRecurring before accessing
item.RecurrencePattern. Just touching that property makes an appointment
recurring. You should only access that property if IsRecurring is true.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"Mark" wrote in message
...
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



Mark November 6th 06 10:17 PM

ItemChange event is modifying my Calendar Events
 
Ken,

Thanks so much! Once I read the words: "touching that property makes an
appointment recurring", I knew exactly what the problem was.

I now check IsRecurring before calling the GetRecurrancePattern method.
Everything works perfectly now.

Thanks again for your prompt, concise and accurate reply.

Mark

"Ken Slovak - [MVP - Outlook]" wrote:

As I mentioned, you need to check IsRecurring before accessing
item.RecurrencePattern. Just touching that property makes an appointment
recurring. You should only access that property if IsRecurring is true.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"Mark" wrote in message
...
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





All times are GMT +1. The time now is 06:42 PM.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2006 OutlookBanter.com