Iram

Hi,

I'm writing an AddIn Outlook application, that should create new Calendar instance.

In this new Calendar I need to check each change in each item if it has any conflicts with other Calendar item.

I tried to use Outlook.AppointmentItem.Conflicts member but its count property always equal to 0. What am I doing wrong

Thanks, Iram.



Re: Visual Studio Tools for Office Outlook.AppointmentItem.Conflicts - Problem

Sue Mosher - Outlook MVP

The Conflicts property does not refer to conflicting times. It refers to conflicts that arise when two users make changes to the same item.

To determine whether the user has appointments that overlap with a given time span, you can use the MAPIFolder.Items.Find message to search over a date range. See http://www.outlookcode.com/article.aspx id=30.





Re: Visual Studio Tools for Office Outlook.AppointmentItem.Conflicts - Problem

Iram

Hi Sue and thanks for your reply.

I read about the Find method and find it helpful, but:

I'm trying to catch conflicts between appointments before the user make any change.

What I'm doing is:

In the BeforeItemMove event I save the time of the appointment before the change

and in the ItemChange event I want to check if there any other appointment that occurs in this period of time.

I wrote this method like that:

private void Items_ItemChange(object item)

{

object objAppointmentItem = null;

try

{

if (flagItemChange == true)//flagItemChange is a flag indicate that this event was raised after the BeforeItemMove event

{

Outlook.AppointmentItem ap = (Outlook.AppointmentItem)item;

if (globalAppointmentID != string.Empty)//globalAppointmentID is a variable that keep the GlobalAppointmentID that initialize in the BeforeItemMove event

{

if (globalAppointmentID.Equals(ap.GlobalAppointmentID))

{

string filter = "(('" + ap.Start.ToShortDateString() + " " + ap.Start.ToShortTimeString() + "'>[Start] And '" + ap.Start.ToShortDateString() + " " + ap.Start.ToShortTimeString() + "'<[End]) Or ('" + ap.End.ToShortDateString() + " " + ap.End.ToShortTimeString() + "'>[Start] And '" + ap.End.ToShortDateString() + " " + ap.End.ToShortTimeString() + "'<[End]) Or ('" + ap.Start.ToShortDateString() + " " + ap.Start.ToShortTimeString() + "'=[Start] And '" + ap.End.ToShortDateString() + " " + ap.End.ToShortTimeString() + "'=[End])) And ('" + ap.GlobalAppointmentID + "' <> [GlobalAppointmentID]) ";

objAppointmentItem = (Outlook.AppointmentItem)_sstFolder.Items.Find(filter);

if ((objAppointmentItem != null) && (((Outlook.AppointmentItem)objAppointmentItem).GlobalAppointmentID!=ap.GlobalAppointmentID))

{

ap.Start = start;

ap.End = end;

ap.Save();

}

}

globalAppointmentID = string.Empty;

}

}

}

catch (Exception ex)

{

string message = ex.Message;

}

finally

{

if (flagItemChange == true)

{

flagItemChange = false;

}

}

}

The problems I have:

1. Error: Condition is not valid .

2. When I replace the " ' " + ap.GlobalAppointmentID + " ' <> [GlobalAppointmentID]) to " ' " + ap.Subject + " ' <> [Subject])

the error is not raised but I get no item return even though I'm sure there is another appointment that should be return for the filter I wrote.

any recommendation Please help, Iram





Re: Visual Studio Tools for Office Outlook.AppointmentItem.Conflicts - Problem

Sue Mosher - Outlook MVP

I dont't read C# very well. Can you give an example of the value you get for filter At a glance it looks way too complicated. As the page I suggested shows, to check for items in a date/time range, you need just one Start expression and one End expression.





Re: Visual Studio Tools for Office Outlook.AppointmentItem.Conflicts - Problem

Iram

Hi,

I get Null for this filter although I should get an appointment.

The filter is a bit complicated because I need to find overlapping appointments ( do you have more efficient filter ) , and because I try to find it inside the event method I should ignore the cuurent item so I should add the ('" + ap.GlobalAppointmentID + "' <> [GlobalAppointmentID]).

But the I have problem with including this statement, maybe I can't include the GlobalAppointmentID property in the filter, so I think I add UserProperty and add it to the filter.

Iram





Re: Visual Studio Tools for Office Outlook.AppointmentItem.Conflicts - Problem

Sue Mosher - Outlook MVP

I wasn't asking what results you get by applying the filter, but was asking for a typical value of the filter string itself. I would definitely test without GlobalAppointmentID. You can always check the results you get for a match. What would be the point of adding UserProperty



Re: Visual Studio Tools for Office Outlook.AppointmentItem.Conflicts - Problem

Iram

Hi,

the point of adding UserProperty is to verify that the item I get using the Find method is the the same item that due to it I get inside the event. As I wrote before I need to check if there any other appointment in the same period that conflicts with the one I'm changing.





Re: Visual Studio Tools for Office Outlook.AppointmentItem.Conflicts - Problem

Sue Mosher - Outlook MVP

GlobalAppointmentID should work find for that-- no need to make extra work adding properties. You can always compare what the IDs from what Items.Restrict returns.

Still waiting to see what the filter string looks like.





Re: Visual Studio Tools for Office Outlook.AppointmentItem.Conflicts - Problem

Iram

Hi,

Here is the filter:

(('6/10/2007 9:30 AM'>[Start] And '6/10/2007 9:30 AM'<[End]) Or ('6/10/2007 10:30 AM'>[Start] And '6/10/2007 10:30 AM'<[End]) Or ('6/10/2007 9:30 AM'=[Start] And '6/10/2007 10:30 AM'=[End]))

I'm trying now to do implemet it as you suggested using .Restrict methos, I'll update you.





Re: Visual Studio Tools for Office Outlook.AppointmentItem.Conflicts - Problem

Sue Mosher - Outlook MVP

You could greatly simplify the filter string if you used the approach detailed in the article I suggested -- look for items that start before the End time and end after the Start time. That will return both overlapping appointments and those fully contained withing the time span.





Re: Visual Studio Tools for Office Outlook.AppointmentItem.Conflicts - Problem

Iram

Hi,

I changed the filter to be like you recommended:

('6/10/2007 9:00 AM'<[End] And '6/10/2007 9:30 AM'>[Start])

which look more efficient from mine, but despite the fact it should return one appointment I get no Items from the .Restrict method.

Is there any thing I'm missing with the .Restrict method Are there some types of appointment that this method does not return

Waiting for your salvation...

Iram





Re: Visual Studio Tools for Office Outlook.AppointmentItem.Conflicts - Problem

Sue Mosher - Outlook MVP

That all looks OK. What about the folder Are you searching in the correct folder I can't tell where your MAPIFolder or Items object is coming from.



Re: Visual Studio Tools for Office Outlook.AppointmentItem.Conflicts - Problem

Iram

Hi Sue,

First of all I have to thank you that you are replying so quickly to my questions!!!

I debbuged the code and checked that the folder's items object really has the number of appointment it should has, and I even checked the dates, but the .Restrict methos does not return any Item.I really confused, I can see in debbug time all the items that belong to the folder but the Restrict does not work...





Re: Visual Studio Tools for Office Outlook.AppointmentItem.Conflicts - Problem

Sue Mosher - Outlook MVP

Did you invoke IncludeRecurrences to make sure you capture any recurring appointment instances



Re: Visual Studio Tools for Office Outlook.AppointmentItem.Conflicts - Problem

Iram

There are no recurring appointment in the Items member