exchangewebservicesews-managed-apiappointment

EWS - Attachment Not Sent With Invitation


I am facing an issue with sending attachments with invitation using EWS Managed API. Appointments attendees are not receiving any attachments added to the appointment but attachment do appears in the calendar of the person that created the appointment.

Here is my code snippet:

try
{
    ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP1, TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time"));
    service.Credentials = new WebCredentials("calendar_user", "password1", "acme");
    service.Url = new Uri("https://acme.com/EWS/Exchange.asmx");

    Appointment appointment = new Appointment(service);
    service.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, "tin.tin@acme.com");

    String UID = "D09F3FF6-1461-414C-89E8-C05BC3B66A4A";
    appointment.ICalUid = UID;
    appointment.Subject = "Test Subject";
    appointment.Body = "Test Content.";
    appointment.Start = new DateTime(2012, 07, 11, 17, 00, 0);
    appointment.End = appointment.Start.AddMinutes(30);

    FileAttachment attachment = appointment.Attachments.AddFileAttachment(@"C:\Users\tintin\Documents\Test.xlsx");
    attachment.IsInline = false;

    appointment.RequiredAttendees.Add("tin.tin@acme.com");

    appointment.Save(SendInvitationsMode.SendToAllAndSaveCopy);
}
catch (Exception ex)
{

}

Solution

  • Look like EWS has horrible limitation with attachment handling. I found a workaround to resolve this issue which requires updating appointment object twice.

    appointment.ICalUid = UID;
    appointment.Subject = "Test Subject";
    appointment.Body = "Test Content.";
    appointment.Start = new DateTime(2012, 07, 11, 17, 00, 0);
    appointment.End = appointment.Start.AddMinutes(30);
    
    FileAttachment attachment = appointment.Attachments.AddFileAttachment(@"C:\Users\tintin\Documents\Test.xlsx");
    attachment.IsInline = false;
    
    appointment.Save(folderCalendar, SendInvitationsMode.SendToNone);
    appointment.RequiredAttendees.Add("tin.tin@acme.com");
    
    appointment.Update(ConflictResolutionMode.AutoResolve, SendInvitationsOrCancellationsMode.SendToAllAndSaveCopy);