EWS Managed API, search based on ICalUid

1.3k views Asked by At
Appointment newAppointment = new Appointment(service);

newAppointment.Subject = "Test Subject";
newAppointment.Start = new DateTime(2017, 01, 05, 17, 00, 0);
newAppointment.StartTimeZone = TimeZoneInfo.Local;
newAppointment.EndTimeZone = TimeZoneInfo.Local;
newAppointment.End = newAppointment.Start.AddMinutes(30);
newAppointment.ICalUid = "asdasda=";
newAppointment.Save();
newAppointment.Body = new MessageBody(BodyType.Text, "test");
newAppointment.RequiredAttendees.Add("[email protected]");

newAppointment.Update(ConflictResolutionMode.AlwaysOverwrite, SendInvitationsOrCancellationsMode.SendOnlyToAll);

ExtendedPropertyDefinition CleanGlobalObjectId = new ExtendedPropertyDefinition(DefaultExtendedPropertySet.Meeting, "ICalUid", MapiPropertyType.String);
PropertySet psPropSet = new PropertySet(BasePropertySet.FirstClassProperties);
psPropSet.Add(CleanGlobalObjectId);
newAppointment.Load(psPropSet);

Folder AtndCalendar = Folder.Bind(service, new FolderId(WellKnownFolderName.Calendar, "[email protected]"));
SearchFilter sfSearchFilter = new SearchFilter.IsEqualTo(CleanGlobalObjectId, "asdasda=");
ItemView ivItemView = new ItemView(1);

FindItemsResults < Item > fiResults = AtndCalendar.FindItems(sfSearchFilter, ivItemView);

if (fiResults.Items.Count > 0) {
 //do whatever
}

This doesnot work for me. And I don't want to use the below piece of code, where we iterate over the calendar view. Have searched at a lot of places and have tried many code pieces.

EWS has no documentation on this. Any kind of help will be appreciated.

DateTime startDate = new DateTime(2016, 10, 1);
DateTime endDate = new DateTime(2017, 12, 1);
CalendarView calView = new CalendarView(startDate, endDate);
3

There are 3 answers

0
pjneary On

If memory serves, you cannot search based on ICalUid. Part of the reason I think is because it's not necessarily unique, in spite of its name. E.g. if you make a meeting and invite two rooms, the ICalUid is the same for the appointments on both rooms' calendars as well as yours.

Why don't you just pick out the ItemId from the appointment you save? I guess there's some other reason beyond what you're showing in the sample code?

0
Glen Scales On

Why don't you use CleanGlobalObjectId which your defining wrongly (that definition your using won't return anything) in your code rather then the IcalUid which is strongly typed property that isn't searchable. Eg EWS - Given an Appointment, get the owner's copy of the Appointment

0
Sidharth Mittal On

using extended properties.

ExtendedPropertyDefinition def = new ExtendedPropertyDefinition(DefaultExtendedPropertySet.PublicStrings, APPOINTMENTIDEXTENDPROPNAME, MapiPropertyType.String);