right way to query calendar items via ews managed api?
Asked Answered
A

1

7

I've got the following code:

var startProp = new ExtendedPropertyDefinition(DefaultExtendedPropertySet.Meeting, "DTSTART", MapiPropertyType.String);
var endProp = new ExtendedPropertyDefinition(DefaultExtendedPropertySet.Meeting, "DTEND", MapiPropertyType.String);

var cond1 = new SearchFilter.IsEqualTo(startProp, StartDate);
var cond2 = new SearchFilter.IsEqualTo(endProp, EndDate);
var filter = new SearchFilter.SearchFilterCollection(LogicalOperator.And, cond1, cond2);
var items = svc.FindItems(WellKnownFolderName.Calendar, filter, view);

I am trying to run this query on an exchange room mailbox. (This is not apparent in the code above however). It may have reservation with the exact start/end time. Hence if there is one reservation matching that criteria, I should get at least one item.

The background to this: think of a meeting room and people are trying to block it for a meeting. On exchange, this is just another mailbox, similar to a user mailbox. So on successful reservation, this mailbox gets an email with the calendar details (iCalendar format (*.ics).

I am stuck on two different counts...

  1. items don't return anything in the code above. The TotalCount is zero. Maybe I am doing something wrong with the api. I am unable to figure this.

  2. I am actually confused with what I am trying to query. I don't understand exchange's resolution in this matter. This is described further below.

So you've email items in a room mailbox. Each email has the calendar embedded with it usually with some base64 encoding. The calendar has a specific schema - we are only interested in the data you find in between VEVENTS (i.e BEGIN:VEVENT and END:VEVENT). The issue here is that there can be multiple VEVENTS sometimes. So how does exchange really do it? Does it run through all the VEVENTS, match the criteria; if it matches successfully, does it return that "email" (with the calendar attached/embedded)? Or it is some other mechanism?

Hence I am unsure of the semantic I've written in the code above. So please advise on this.

Agger answered 7/8, 2016 at 12:48 Comment(0)
A
1

Found the answer to the first part:

static void Find(DateTime Start, DateTime End, ExchangeService svc)
{
    var filter1 = new SearchFilter.IsGreaterThanOrEqualTo(MeetingRequestSchema.Start, Start);
    var filter2 = new SearchFilter.IsLessThanOrEqualTo(MeetingRequestSchema.End, End);
    var filter = new SearchFilter.SearchFilterCollection(LogicalOperator.And, filter1, filter2);
    var vw = new ItemView(99);
    var items = svc.FindItems(WellKnownFolderName.Calendar, filter, vw);

    Console.WriteLine("Count: {0}", items.TotalCount);

}
Agger answered 8/8, 2016 at 12:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.