title: EWS Managed Api - Retrieve calendar items only once
body: <p>I've got a windows service to read calendar items from Exchange and store them in my application's DB against each user.
  Now I wonder what is the best way to mark an item on Exchange to not be retrieved in the next service run after storing it?</p>
  
  <p>I tried to add an extended property to the calendar item and set it's value and then search based on it's value each time:</p>
  
  <pre><code>DateTime startDate = DateTime.Now;
  DateTime endDate = startDate.AddDays(60);
  const int NUM_APPTS = 60;    
  // Set the start and end time and number of appointments to retrieve.
  CalendarView cView = new CalendarView(startDate, endDate, NUM_APPTS);
  
  Guid myPropertyId = new Guid("{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}");
  ExtendedPropertyDefinition myExtendedProperty = new ExtendedPropertyDefinition(myPropertyId, "SyncFlag", MapiPropertyType.Boolean);
  
  // Limit the properties returned to the appointment's subject, start time, end time and the extended property.
   cView.PropertySet = new PropertySet(AppointmentSchema.Subject, AppointmentSchema.Start, AppointmentSchema.End, AppointmentSchema.Location, myExtendedProperty);
  
  // Retrieve a collection of appointments by using the calendar view.
  List&lt;SearchFilter&gt; searchFilterCollection = new List&lt;SearchFilter&gt;();
  searchFilterCollection.Add(new SearchFilter.IsEqualTo(AppointmentSchema.Start, DateTime.Now));
  searchFilterCollection.Add(new SearchFilter.IsEqualTo(AppointmentSchema.End, DateTime.Now.AddDays(60)));
  
  searchFilterCollection.Add(new SearchFilter.IsNotEqualTo(myExtendedProperty, true)); //Do not fetch already marked calendar items
  
  SearchFilter searchFilter = new SearchFilter.SearchFilterCollection(LogicalOperator.And, searchFilterCollection);
  
  FindItemsResults&lt;Item&gt; appointments = service.FindItems(WellKnownFolderName.Calendar, searchFilter, cView);
  </code></pre>
  
  <p>Searching calendar items using this code throws this exception:</p>
  
  <blockquote>
    <p><em>Restrictions and sort order may not be specified for a CalendarView.</em></p>
  </blockquote>
  
  <p>And I'm not sure if it's the best way to do it either. Any idea?</p>
  
  <p>Thanks</p>