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

时间:2017-06-28 15:06:09

标签: c# outlook exchangewebservices appointment

我正在开发使用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);       
}

我的代码中有任何问题吗? 请帮忙。

感谢

1 个答案:

答案 0 :(得分: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);