2017-06-28 91 views
0

我正在開發使用EWS託管API向Outlook收件人發送約會的應用程序, 現在需要向約會添加附件,我可以將附件附加到電子郵件,但是當我使用與附加項目附件相同的技術時電子郵件,但附件不附加,我的代碼如下如何使用EWS將文件附件添加到約會?

 public string sendCalanderEvntAsReply(EntityLayer.Data_Contracts.AppointmentDTO appointment) 
     { 

       Appointment app = new Appointment(service); 
       app.Subject = appointment.Subject; 
       app.Body = appointment.Body; 
       app.Start = Convert.ToDateTime(appointment.Start); 
       app.End = Convert.ToDateTime(appointment.End); 
       app.Location = appointment.Location; 

       foreach (string obj in appointment.Attendees) 
       { 
        app.RequiredAttendees.Add(obj); 
       } 

       if (appointment.Attachments != null && 
        appointment.Attachments.Count > 0) 
       { 
        foreach (var att in appointment.Attachments) 
        { 
         app.Attachments.AddFileAttachment(att.FileName); 
        } 
       } 

       app.Save(SendInvitationsMode.SendToAllAndSaveCopy);  
} 

有沒有問題在我的代碼? 請幫忙。

感謝

回答

3

隨着EWS當你想送你需要先保存預約您發送其他消息之前,你將只能得到固定的業主與您的代碼複製這樣的會議邀請函的附件您應使用類似

  Appointment app = new Appointment(service); 
      app.Subject = appointment.Subject; 
      app.Body = appointment.Body; 
      app.Start = Convert.ToDateTime(appointment.Start); 
      app.End = Convert.ToDateTime(appointment.End); 
      app.Location = appointment.Location; 



      if (appointment.Attachments != null && 
       appointment.Attachments.Count > 0) 
      { 
       foreach (var att in appointment.Attachments) 
       { 
        app.Attachments.AddFileAttachment(att.FileName); 
       } 
      } 
      app.Save(SendInvitationsMode.SendToNone); 

      foreach (string obj in appointment.Attendees) 
      { 
       app.RequiredAttendees.Add(obj); 
      } 

      app.Update(ConflictResolutionMode.AutoResolve, SendInvitationsOrCancellationsMode.SendToAllAndSaveCopy); 
+0

謝謝@格蘭它的工作.. – Roshan

+0

我有一個類似的問題,當刪除附件和添加新的。但是這個解決方案對我不起作用。這裏是我的情況,如果你可能有一瞥:https://stackoverflow.com/questions/48658409/how-to-update-delete-file-attachments-to-appointment-using-ews –

相關問題