I add an extended property in this way:
ExtendedPropertyDefinition ep = new ExtendedPropertyDefinition(DefaultExtendedPropertySet.CalendarAssistant, "AppointmentID", MapiPropertyType.Integer);
Appointment newApp = new Appointment(service);
newapp.SetExtendedProperty(ep, appID);
newApp.Save(SendInvitationsMode.SendToNone);
All is good. The appointment shows up in Outlook as expected.
Later I tried to search through all Outlook appointment with an AppointmentID assigned by:
List<SearchFilter> filters = new List<SearchFilter>();
filters.Add(new SearchFilter.Exists(ep));
filters.Add(new SearchFilter.IsLessThan(AppointmentSchema.Start, DateTime.Now.AddDays(60)));
filters.Add(new SearchFilter.IsGreaterThanOrEqualTo(AppointmentSchema.Start, DateTime.Today));
FindItemsResults<Item> allOutlookAppt = service.FindItems(WellKnownFolderName.Calendar, new SearchFilter.SearchFilterCollection(LogicalOperator.And, filters.ToArray()), viewFind);
allOutlookAppt returns the expected collection (calendar entries with AppointmentID set). However I could not retrieve the AppointmentID by this code:
foreach (var a in allOutlookAppt) // contains correct calendar entries!
{
object oid;
if (a.TryGetProperty(ep, out oid))
{
// a.TryGetProperty is always false, oid is always null thus never enter here!
}
}
What did I do wrong?
Edit: I tried a.ExtendedProperties.Count and it actually returns 0.