0

I'm using C# to go through and get all of my appointments in my outlook calender and trying to figure out if I have any conflicts, but when I check Appointment.Conflicts.Count, it's always 0, even though I've added multiple appointments that occur at the same time.

Here's some example code:

var outlook = new Microsoft.Office.Interop.Outlook.Application();
var calendar = outlook.Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar);

Outlook.AppointmentItem appointment;
foreach (Outlook.AppointmentItem item in calendar.Items)
{
    if (item.Conflicts.Count > 0)
    {
        Console.WriteLine("Never gets hit");
    }

}

How do I determine if an appointment in Outlook conflicts with another appointment programmatically in C#?

Daryl
  • 18,592
  • 9
  • 78
  • 145
  • You may want to look at [this answer](http://stackoverflow.com/questions/158706/how-to-properly-clean-up-excel-interop-objects-in-c-sharp/158752#158752) if you are having cleanup issues. – Jeff Mercado Nov 14 '11 at 20:11
  • @JeffMercado I'm not having any cleanup issues. I'm assuming that item.Conflicts.Count will give me the number of appointments the current appointment is overlapping with time wise (conflicting). It's always giving 0, even though I have appointments that overlap (one starts before another finishes. – Daryl Nov 14 '11 at 20:58
  • Actually what I was referring to was the code you have now will have issues properly cleaning up the outlook process. I don't really know what the problem that you're asking about. You have a different issue where you have resources, `outlook.Application` and `outlook.Application.Session` that get acquired and not cleaned up. If you look in task manager, you will probably see instances of outlook running even after you close your program because of this. See the answer there on why. – Jeff Mercado Nov 15 '11 at 01:14

1 Answers1

1

It appears the Conflicts property is only for dealing with edit conflicts, not with scheduling conflicts.

See: Conflict Resolution for Standard Outlook Item Types

Also note that nearly all of the outlook item types also have a conflicts property, even those that don't have scheduling properties (e.g. NoteItem).

It appears you will have to examine the date ranges yourself via the appointmentItem.Start and appointmentItem.End properties, and perhaps the AllDayEvent property as well.

Nathan
  • 10,593
  • 10
  • 63
  • 87
  • There are also issues with getting recurring appointments as well. Outlook seems to make things more complicated than they need to, but you are right... the conflicts refer to issues syncing the item between the outlook server, and the local client (say you updated an appointment on your local machine, and from the web client) – Daryl Nov 20 '11 at 19:59