3

We have a need to export calendar data from our Exchange Server 2013 so that we can provide our calendar information to another company.

  1. Export from Exchange Server 2013
  2. Export to iCalendar files (ics), CSV, or some other easy to work with format
  3. Dumps resulting information into a folder on a computer
  4. No cloud or hosted solutions
  5. Prefer an exe or a deployable web application. Possibly a Powershell, batch file, Python or similar
  6. Does not need Outlook to function - it should talk directly to Exchange (probably via Exchange Web Services).
  7. Should support exporting calendar info for all Exchange hosted calendars (not just one calendar)
0

I could not find a prebuilt tool. But I created a stub tool that makes use of Exchange Web Services and DDay.iCal libraries. You'd obviously want to flesh the implementation out more, this was just 10 minutes of coding.

ExchangeService service = new ExchangeService();                                                                          //EWS Managed API
service.Credentials = new NetworkCredential("DOMAIN\\username", "password");                               //should replace with service account
service.AutodiscoverUrl("user@domain.com");                                                                  //This tells it where to look for Exchange
var startDate = new DateTime(2015, 1, 1);                                                                                 //start date of calendar events to retrieve
var endDate = new DateTime(2015, 12, 31);                                                                                 //end date of calendar events to retrieve                    
var results = service.FindAppointments(WellKnownFolderName.Calendar, new CalendarView(startDate, endDate));               //pull calendar events from Exchange
var iCal = new iCalendar();                                                                                               //Item to store the iCal events
foreach (var result in results)                                                                                           //loop over the retrieved calendar events from Exchange
{
    var iCalEvent = iCal.Create<Event>();                                                                                 //create a new iCal event to hold the event properties
    iCalEvent.Summary = "Hidden " + result.Subject;                                                                       //copy the subject. Will replace with “Busy” on production                   
    iCalEvent.Start = new iCalDateTime(result.Start);                                                                     //copy start time
    iCalEvent.End = new iCalDateTime(result.End); );                                                                      //copy end time
}
var iCalText = new iCalendarSerializer().SerializeToString(iCal);                                                         //Create the ics formatted string
MailMessage message = new MailMessage();                                                                                  //Create email to send
message.Subject = "iCal Test";                                                                                            //Set email subject
message.Body = "attached";                                                                                                //set email body
message.To.Add(new MailAddress("recipent@domain.com"));                                                          //set email destination
message.From = new MailAddress("from@domain.com");                                                                       //set email from address
byte[] fileBytes = System.Text.Encoding.UTF8.GetBytes (iCalText);                                                         //convert string to file bytes
message.Attachments.Add(new System.Net.Mail.Attachment(new MemoryStream(fileBytes), "calendar.ics","text/calendar"));     //create attachment from file bytes
SmtpClient client = new SmtpClient("mail.domain.com");                                                                   //create email client for our exchange server
client.Send(message);                                                                                                     //send the email
Console.WriteLine("Press any key to exit.");
Console.ReadKey();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.