C
Crash
Windows XP SP2
C# .NET v1.1
Outlook 2003 {via Office 11.0 PIA}
I'm manipulating Outlook's calendar via OLE automation from my C#
application. I would like to iterate through the calendar items
collection and delete appointments from the items collection based on
some business rules. However after I delete/remove items I am getting
"index out of range" and/or "object has been moved or deleted" errors.
Also, sometimes it seems that the item collection's Count property does
not acknowledge that I have deleted something during a loop iteration -
has anybody seen this behavior?
Question: What is the correct & proper way to delete a calendar item
while iterating the items collection? Is it AppointmentItem.Delete()
or is it Items.Remove(index)??
Pseudo code, note that I don't use a foreach loop because I need to
modify the collection:
int i = 1;
while (i <= items.Count)
{
AppointmentItem ai = (AppointmentItem) items;
if (<<my business rules>>)
{
ai.Delete(); // --> or items.Remove(i) ????
}
else
{
<<my other action>>
++i;
}
}
C# .NET v1.1
Outlook 2003 {via Office 11.0 PIA}
I'm manipulating Outlook's calendar via OLE automation from my C#
application. I would like to iterate through the calendar items
collection and delete appointments from the items collection based on
some business rules. However after I delete/remove items I am getting
"index out of range" and/or "object has been moved or deleted" errors.
Also, sometimes it seems that the item collection's Count property does
not acknowledge that I have deleted something during a loop iteration -
has anybody seen this behavior?
Question: What is the correct & proper way to delete a calendar item
while iterating the items collection? Is it AppointmentItem.Delete()
or is it Items.Remove(index)??
Pseudo code, note that I don't use a foreach loop because I need to
modify the collection:
int i = 1;
while (i <= items.Count)
{
AppointmentItem ai = (AppointmentItem) items;
if (<<my business rules>>)
{
ai.Delete(); // --> or items.Remove(i) ????
}
else
{
<<my other action>>
++i;
}
}