如何使用 EWS 导出 .ics 文件中的所有约会?

How can I export all the Appointments in .ics file using EWS?

我正在使用 EWS 来管理 Exchange Server 电子邮件帐户的操作。如何导出 .ics 文件中的所有日历约会? 我试过关注

string iCalFileName = Path.Combine(Path.GetTempPath(), "appointments.ics");
foreach (Appointment appointment in service.FindItems(WellKnownFolderName.Calendar, new ItemView(int.MaxValue)))
{
    appointment.Load();
    using (FileStream fs = new FileStream(iCalFileName, FileMode.Create, FileAccess.Write))
    {
        using (StreamWriter s = new StreamWriter(fs))
        {
            s.WriteLine(appointment.MimeContent.Content);//error must load property before using it
        }
    }
}

任何人都可以告诉我我在这里缺少什么吗?

当您使用 FindItem 时,不会返回 MimeContent(以及许多其他属性),您需要对每个项目进行单独的 GetItem 调用以检索它。最好的办法是使用 LoadPropertiesFromItems,它将在 Managed API 中批处理 GetItem 请求,请参阅 http://blogs.msdn.com/b/exchangedev/archive/2010/03/16/loading-properties-for-multiple-items-with-one-call-to-exchange-web-services.aspx

干杯 格伦