【问题标题】:How to add file attachments to appointment using EWS?如何使用 EWS 将文件附件添加到约会中?
【发布时间】:2017-06-28 15:06:08
【问题描述】:

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

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

谢谢

【问题讨论】:

    标签: c# outlook exchangewebservices appointment


    【解决方案1】:

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

    【讨论】:

    • 我在删除附件和添加新附件时遇到了类似的问题。但是这个解决方案对我不起作用。这是我的情况,如果您可能可以一瞥:stackoverflow.com/questions/48658409/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-25
    • 2017-08-27
    • 1970-01-01
    相关资源
    最近更新 更多