如何使用 EWS 将文件附件添加到约会?

How to add file attachments to appointment using EWS?

我正在开发使用 EWS 管理的应用程序 API 向 outlook 收件人发送约会, 现在需要为约会添加附件,我可以将附件附加到电子邮件,但是当我使用与将项目附件附加到电子邮件相同的技术时,但附件没有附加,我的代码如下

       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);       
}

我的代码有什么问题吗? 请帮忙

谢谢

使用 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);