A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Add-ins for Outlook
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Outlook 2007 add-in: appointment changed event



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old July 29th 08, 02:23 PM posted to microsoft.public.outlook.program_addins
Johan Machielse[_2_]
external usenet poster
 
Posts: 11
Default Outlook 2007 add-in: appointment changed event

Dear reader,

I've created an add-in for Outlook 2007; this add-in sets the color of the
appointments related to the location.

- In the OnStartupComplete() event all appointments will be colored.
- In the Outlook.MAPIFolder.AddItem event new appointmets will be colored.

But, it goes wrong with the Outlook.MAPIFolder.ChangeItem event...

//_calendarItems is of type Outlook.MAPIFolder
_calendarItems.ItemChange += new
Microsoft.Office.Interop.Outlook.ItemsEvents_ItemC hangeEventHandler(Items_ItemChange);

//ItemChange event handler
void Items_ItemChange(object Item)
{
Outlook.AppointmentItem appointment = (Outlook.AppointmentItem)Item;
SetColorAppointment(appointment);
}

//changes color appointment (called within all events mentioned above)
private void SetColorAppointment(Outlook.AppointmentItem appointment)
{
int color = GetLocationColor(appointment.Location);


appointment.PropertyAccessor.SetProperty"http://schemas.microsoft.com/mapi/id/
{00062002-0000-0000-C000-000000000046}/82140003",
color);
appointment.Save();

}

When the SetColorAppointment() has been called; the event Item_ItemChange()
will be called again and again and again, because the item changed off
course! How can this behavour be solved?

I also tried this version of the SetColorAppointment() method (with
Redemption); the Items_ItemChange() will also be called again and again...

Rdo.SafeAppointmentItem safeAppointment = new Rdo.SafeAppointmentItem();
safeAppointment.Item = appointment;
int propertyID =
safeAppointment.GetIDsFromNames("{00062002-0000-0000-C000-000000000046}",
0x8214);
propertyID = propertyID | 0x3;
safeAppointment.set_Fields(propertyID, color);
//appointment.Subject = appointment.Subject;
appointment.Save();

I also tried using the Outlook.AppointmentItem.PropertyChange event. This
event fires when the Location property has been changed but when I handle
this event and try to set the colors of all appointments; the appointment
wherefrom I just changed the location still has the old location??? I checked
it and the case is that the I continuously change the color of the previous
location! During this event it seems like I don't have the current MAPIFolder
with the current appointment items?

void appointment_PropertyChange(string Name)
{
if ( Name == "Location" )
{
foreach (Outlook.AppointmentItem appointment in _items)
{
SetColorAppointment(appointment);
}
}
}

In Outlook 2003 I got it working with the Redemption method and
PropertyChange event, but this approach does not seem to work in Outlook
2007...

What is the best solution to catch the event that the location has been
changed of an appoinment and changing the color successfully in Outlook 2007?

Thank you in advance,

Johan Machielse

Ads
  #2  
Old July 29th 08, 02:34 PM posted to microsoft.public.outlook.program_addins
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default Outlook 2007 add-in: appointment changed event

Setting a property of an item in ItemChange() will of course cause that
event to fire again. So you need to put a flag on the item as you change the
color to show it was already changed. An alternative would be to maintain a
list of items that have been changed in that event handler and if the item
is already in the list then don't change it again.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"Johan Machielse" wrote in
message ...
Dear reader,

I've created an add-in for Outlook 2007; this add-in sets the color of the
appointments related to the location.

- In the OnStartupComplete() event all appointments will be colored.
- In the Outlook.MAPIFolder.AddItem event new appointmets will be colored.

But, it goes wrong with the Outlook.MAPIFolder.ChangeItem event...

//_calendarItems is of type Outlook.MAPIFolder
_calendarItems.ItemChange += new
Microsoft.Office.Interop.Outlook.ItemsEvents_ItemC hangeEventHandler(Items_ItemChange);

//ItemChange event handler
void Items_ItemChange(object Item)
{
Outlook.AppointmentItem appointment = (Outlook.AppointmentItem)Item;
SetColorAppointment(appointment);
}

//changes color appointment (called within all events mentioned above)
private void SetColorAppointment(Outlook.AppointmentItem appointment)
{
int color = GetLocationColor(appointment.Location);


appointment.PropertyAccessor.SetProperty"http://schemas.microsoft.com/mapi/id/
{00062002-0000-0000-C000-000000000046}/82140003",
color);
appointment.Save();

}

When the SetColorAppointment() has been called; the event
Item_ItemChange()
will be called again and again and again, because the item changed off
course! How can this behavour be solved?

I also tried this version of the SetColorAppointment() method (with
Redemption); the Items_ItemChange() will also be called again and again...

Rdo.SafeAppointmentItem safeAppointment = new Rdo.SafeAppointmentItem();
safeAppointment.Item = appointment;
int propertyID =
safeAppointment.GetIDsFromNames("{00062002-0000-0000-C000-000000000046}",
0x8214);
propertyID = propertyID | 0x3;
safeAppointment.set_Fields(propertyID, color);
//appointment.Subject = appointment.Subject;
appointment.Save();

I also tried using the Outlook.AppointmentItem.PropertyChange event. This
event fires when the Location property has been changed but when I handle
this event and try to set the colors of all appointments; the appointment
wherefrom I just changed the location still has the old location??? I
checked
it and the case is that the I continuously change the color of the
previous
location! During this event it seems like I don't have the current
MAPIFolder
with the current appointment items?

void appointment_PropertyChange(string Name)
{
if ( Name == "Location" )
{
foreach (Outlook.AppointmentItem appointment in _items)
{
SetColorAppointment(appointment);
}
}
}

In Outlook 2003 I got it working with the Redemption method and
PropertyChange event, but this approach does not seem to work in Outlook
2007...

What is the best solution to catch the event that the location has been
changed of an appoinment and changing the color successfully in Outlook
2007?

Thank you in advance,

Johan Machielse


  #3  
Old July 29th 08, 03:09 PM posted to microsoft.public.outlook.program_addins
Johan Machielse[_2_]
external usenet poster
 
Posts: 11
Default Outlook 2007 add-in: appointment changed event

Yep, I ready figured it out! I used a flag to check if the appointment was
already changed!

Thank you Ken!

Johan

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

Setting a property of an item in ItemChange() will of course cause that
event to fire again. So you need to put a flag on the item as you change the
color to show it was already changed. An alternative would be to maintain a
list of items that have been changed in that event handler and if the item
is already in the list then don't change it again.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"Johan Machielse" wrote in
message ...
Dear reader,

I've created an add-in for Outlook 2007; this add-in sets the color of the
appointments related to the location.

- In the OnStartupComplete() event all appointments will be colored.
- In the Outlook.MAPIFolder.AddItem event new appointmets will be colored.

But, it goes wrong with the Outlook.MAPIFolder.ChangeItem event...

//_calendarItems is of type Outlook.MAPIFolder
_calendarItems.ItemChange += new
Microsoft.Office.Interop.Outlook.ItemsEvents_ItemC hangeEventHandler(Items_ItemChange);

//ItemChange event handler
void Items_ItemChange(object Item)
{
Outlook.AppointmentItem appointment = (Outlook.AppointmentItem)Item;
SetColorAppointment(appointment);
}

//changes color appointment (called within all events mentioned above)
private void SetColorAppointment(Outlook.AppointmentItem appointment)
{
int color = GetLocationColor(appointment.Location);


appointment.PropertyAccessor.SetProperty"http://schemas.microsoft.com/mapi/id/
{00062002-0000-0000-C000-000000000046}/82140003",
color);
appointment.Save();

}

When the SetColorAppointment() has been called; the event
Item_ItemChange()
will be called again and again and again, because the item changed off
course! How can this behavour be solved?

I also tried this version of the SetColorAppointment() method (with
Redemption); the Items_ItemChange() will also be called again and again...

Rdo.SafeAppointmentItem safeAppointment = new Rdo.SafeAppointmentItem();
safeAppointment.Item = appointment;
int propertyID =
safeAppointment.GetIDsFromNames("{00062002-0000-0000-C000-000000000046}",
0x8214);
propertyID = propertyID | 0x3;
safeAppointment.set_Fields(propertyID, color);
//appointment.Subject = appointment.Subject;
appointment.Save();

I also tried using the Outlook.AppointmentItem.PropertyChange event. This
event fires when the Location property has been changed but when I handle
this event and try to set the colors of all appointments; the appointment
wherefrom I just changed the location still has the old location??? I
checked
it and the case is that the I continuously change the color of the
previous
location! During this event it seems like I don't have the current
MAPIFolder
with the current appointment items?

void appointment_PropertyChange(string Name)
{
if ( Name == "Location" )
{
foreach (Outlook.AppointmentItem appointment in _items)
{
SetColorAppointment(appointment);
}
}
}

In Outlook 2003 I got it working with the Redemption method and
PropertyChange event, but this approach does not seem to work in Outlook
2007...

What is the best solution to catch the event that the location has been
changed of an appoinment and changing the color successfully in Outlook
2007?

Thank you in advance,

Johan Machielse



 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I lock an appointment so it can not be changed? mjs Outlook - Calandaring 12 June 25th 08 05:14 PM
why appointment.LastModificationTime isn't changed? Cynthia Add-ins for Outlook 3 December 27th 07 06:42 PM
an event or appointment in the calendar in outlook 2007 does not w izzy Outlook - Calandaring 3 June 21st 07 01:47 AM
itemchange event in public (exchange) folder occurs if nothing is changed MIchael Outlook and VBA 7 May 23rd 07 11:04 PM
Changes to Contact Item are not displayed if changed in New_Inspector-Event cs Add-ins for Outlook 1 December 8th 06 06:40 PM


All times are GMT +1. The time now is 09:18 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.