Search code examples
c#winformsexchangewebservicesexchange-server-2007

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


I am using EWS to manage operations of Exchange Server email accounts. How can I export all the Appointments of calendar in the .ics file? I have tried by following.

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

Can anybody suggest me what I am missing here?


Solution

  • The MimeContent (and a number of other properties) aren't returned when you use FindItem you need to make a separate GetItem call on each item to retrieve that. The best thing to do is use LoadPropertiesFromItems which will batch the GetItem request in the Managed API see http://blogs.msdn.com/b/exchangedev/archive/2010/03/16/loading-properties-for-multiple-items-with-one-call-to-exchange-web-services.aspx

    Cheers Glen