2

This is the code for accessing my outlook calendar items, change their subjects, add some extended property and update it self. But I am getting an error as

At least one recipient isn't valid

when I'm trying to update the item. I believe that there are no any invalid recipient in the item. Why am I getting this error and how am I overcome this. Please advice me. Thank you.

Here is the code :

public void AccessCalendarItems()
{
    // Specify a view that returns up to 1000 items.
    ItemView view = new ItemView(1000);

    // Specify a calendar view for returning instances between matching dates.
    DateTime startDate = new DateTime(2015, 5, 1);
    DateTime endDate = new DateTime(2015, 9, 1);
    CalendarView calView = new CalendarView(startDate, endDate);

    //string querystring = "Subject:'Doctor'";

    try
    {              
        // Find all the appointments in the calendar based on the dates set in the CalendarView. - Currently Disabled
        // Find all the appointments in the calendar based on the sunject content (get first 1000 items)
        int i = 123123;
        SearchFilter subjectFilter = new SearchFilter.ContainsSubstring(AppointmentSchema.Subject, "Doctor");
        FindItemsResults<Item> instanceResults = service.FindItems(WellKnownFolderName.Calendar, subjectFilter, view);

        foreach (Item item in instanceResults.Items)
        {
            Appointment appointment = item as Appointment;
            MessageBox.Show(appointment.Subject);
            appointment.Subject = appointment.Subject + " - KR";
            ExtendedPropertyDefinition extendedPropertyDefinition = new ExtendedPropertyDefinition(DefaultExtendedPropertySet.PublicStrings, "BookingKey", MapiPropertyType.String);
            appointment.SetExtendedProperty(extendedPropertyDefinition, i);
            appointment.Update(ConflictResolutionMode.AutoResolve);
            i++;
        }
    }
    catch (Exception ex)
    {
        MessageBox.Show("Error: " + ex.Message);
    }
}

Thanks for helping, Kushan Randima.

krlzlx
  • 5,752
  • 14
  • 47
  • 55
  • I just checked the item that I got an exception (error) from this code while I was trying to update() it. It has updated properly (Subject has altered, Extended properties also added) –  May 11 '15 at 08:23

1 Answers1

3

Try using the overload version of Update that supports passing the SendInvitationsOrCancellationsMode enum, and pass SendInvitationsOrCancellationsMode.SendToNone. This will ensure that the server doesn't try to send meeting updates to attendees.

Jason Johnston
  • 17,194
  • 2
  • 20
  • 34
  • Is there any other way to solve this, the error is pretty unclear - does EWS send any updates/cancelations before throwing the error? In which case sending to `SendToNone` means no one receives an update? – Stephen Binns Nov 09 '17 at 15:59