title: c# outlook delete all appointments
body: <pre><code>Microsoft.Office.Interop.Outlook.Application outlookApp = new Microsoft.Office.Interop.Outlook.Application();
  Microsoft.Office.Interop.Outlook.MAPIFolder calendarFolder = outlookApp.Session.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderCalendar);
  
  Console.WriteLine(calendarFolder.Items.Count);
  
  foreach (Microsoft.Office.Interop.Outlook.AppointmentItem c in calendarFolder.Items)
  {
  
          Console.WriteLine(c.Subject.ToString() + " " + c.Start.ToString() + " deleted");
  
          c.Delete();
  
  }
  </code></pre>
  
  <p>This deletes appointments, but only chucks at a time,if you keep re-running this it eventually deletes them all...</p>
  
  <p>does anyone know what is going on, I also tried to Sort it first, no change--</p>
  
  <p>Thanks!!</p>
  
  <p>after experimenting, looping backwards did it-- not really sure why however</p>
  
  <pre><code>   Console.WriteLine(calendarFolder.Items.Count);
     Microsoft.Office.Interop.Outlook.Items calendarItems = calendarFolder.Items;
     //Microsoft.Office.Interop.Outlook.AppointmentItem app = calendarItems as  Microsoft.Office.Interop.Outlook.AppointmentItem;
  
     //for (int i = 1; i &lt;= calendarFolder.Items.Count; i++)
     for (int i = calendarFolder.Items.Count; i &gt; 0; i--)
      {
          calendarFolder.Items[i].Delete();
  
          //app = calendarFolder.Items[i];
          Console.WriteLine(i);
          //app.Delete();
      }
  </code></pre>