Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

right way to query calendar items via ews managed api?

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.

like image 217
deostroll Avatar asked Aug 07 '16 12:08

deostroll


People also ask

Does Free Busy use EWS?

FreeBusy uses EWS (Exchange Web Services) protocol, not ActiveSync. EWS is typically deployed together with OWA (Outlook Web App). If your company offers OWA to employees, then you can use FreeBusy, and you can sign up on your own without assistance from your IT department.

Does OWA use EWS?

This option can be useful when you don't have your Outlook app at hand. Still, in companies using Exchange Online, OWA and EWS can go hand-in-hand. For example, your employees can use OWA to check their emails, access their calendars, revise their To-Do lists, all without being on their device.


1 Answers

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);

}
like image 60
deostroll Avatar answered Sep 24 '22 18:09

deostroll