By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,275 Members | 936 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,275 IT Pros & Developers. It's quick & easy.

Exception Removing/Deleting Appointment??

P: n/a

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[i];

if (<<my business rules>>)
{
ai.Delete(); // --> or items.Remove(i) ????
}
else
{
<<my other action>>
++i;
}
}

Nov 17 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Use a down counting loop or a Do loop that tests for any items still
remaining.

--
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
"Crash" <so*********@san.rr.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...

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[i];

if (<<my business rules>>)
{
ai.Delete(); // --> or items.Remove(i) ????
}
else
{
<<my other action>>
++i;
}
}


Nov 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.