4

When i am inserting the appointment into exchange, i got the following issue "EndDate is earlier than StartDate", could any one please help to resolve this?

Appointment appt=new Appointment();
appt.Start=DateTime.Now();
appt.End=DateTime.Now().Addhours(1);
appt.Subject="Test";
appt.Save(WellKnownFolderName.Calendar);

in the last line i got the issue, but i am giving the correct start and end date, could anyone please tell me why i got this issue?

Note: if i am giving the different date in start and end date it will accept. start and end date should be same and time only difference, in this scenario only i got this issue. please help me to resolve this

sandal raj
  • 41
  • 1
  • 5

2 Answers2

1

I ran into a very similar problem today, but when updating an event. I believe my solution is relevant to the question.

I was updating an event which was created in the Central Europe timezone. My code was setting the properties in the following order:

appt.Start = DateTime.UtcNow;
appt.End = DateTime.UtcNow.AddMinutes(30);
appt.StartTimeZone = TimeZoneInfo.FindSystemTimeZoneById("UTC");
appt.EndTimeZone = TimeZoneInfo.FindSystemTimeZoneById("UTC");

Working with the Managed Api, I was under the impression that the order of property assignments has no impact on the actual operation, however in this case I found it not to be true.

The Managed Api generated the following XML:

<soap:Body>
        <m:UpdateItem ConflictResolution="AlwaysOverwrite" SendMeetingInvitationsOrCancellations="SendToNone">
            <m:SavedItemFolderId>
                <t:FolderId Id="AQMkADJkAAA==" />
            </m:SavedItemFolderId>
            <m:ItemChanges>
                <t:ItemChange>
                    <t:ItemId Id="AAMkADJkZWZiODMxLWNRE" />
                    <t:Updates>
                        <t:SetItemField>
                            <t:FieldURI FieldURI="calendar:EndTimeZone" />
                            <t:CalendarItem>
                                <t:EndTimeZone Name="UTC" Id="UTC">
                                    ...
                                </t:EndTimeZone>
                            </t:CalendarItem>
                        </t:SetItemField>
                        <t:SetItemField>
                            <t:FieldURI FieldURI="calendar:Start" />
                            <t:CalendarItem>
                                <t:Start>2015-10-19T15:30:00.000Z</t:Start>
                            </t:CalendarItem>
                        </t:SetItemField>
                        <t:SetItemField>
                            <t:FieldURI FieldURI="calendar:End" />
                            <t:CalendarItem>
                                <t:End>2015-10-19T16:00:00.000Z</t:End>
                            </t:CalendarItem>
                        </t:SetItemField>
                        ...
                        <t:SetItemField>
                            <t:FieldURI FieldURI="calendar:StartTimeZone" />
                            <t:CalendarItem>
                                <t:StartTimeZone Name="UTC" Id="UTC">
                                    ...
                                </t:StartTimeZone>
                            </t:CalendarItem>
                        </t:SetItemField>
                    </t:Updates>
                </t:ItemChange>
            </m:ItemChanges>
        </m:UpdateItem>
    </soap:Body>

Switching the order of property assignments to set the timezones first fixed the problem for me.

Also problem does not occur when the original timezone on the event is equal to the timezones being set. Just when switching the timezones.

Please note that this is not meant to be the real solution. A better one would be to clone the managed api and fix the problem in the library.

Jakub Kaleta
  • 1,740
  • 1
  • 18
  • 25
0

Maybe the problem is timezone. When you use Now the timezone DateTimeKind.Local which is not recomended by Working with Time Zones in Exchange 2010 Exchange Web Services. Would you try something as appt.Start = new DateTime(2010, 2, 12, 10, 0, 0, DateTimeKind.Unspecified); ?
I use Exchange2007 and your code works for me, but timezone handling is changed in 2010.

IvanH
  • 5,039
  • 14
  • 60
  • 81