Skip to content

Instantly share code, notes, and snippets.

@anlai
Created May 30, 2012 14:32
Show Gist options
  • Save anlai/2836671 to your computer and use it in GitHub Desktop.
Save anlai/2836671 to your computer and use it in GitHub Desktop.
Sample Exchange Usage of MyAppointment class described in blog post http://anlai.wordpress.com/2011/06/22/exchange-calendar-syncing-with-exchange-web-services-ews-api/
public class ExchangeFunctions
{
private const string _username = "uname";
private const string _password = "password";
private const string _domain = "domain";
public static string CreateAppointment(string mailboxId, MyAppointment appt)
{
var service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
service.Credentials = new WebCredentials(_username, _password, _domain);
// auto loads the url for the targetted mailbox
service.AutodiscoverUrl(mailboxId);
var appointment = ConvertAppointment(service, appt);
// save the appointment, bound to the targetted user's mailbox, using delegate permissions
appointment.Save(new FolderId(WellKnownFolderName.Calendar, mailboxId));
}
// Convert My Appointment to Exchange Appointment class
private Appointment ConvertAppointment(ExchangeService service, MyAppointment appt)
{
// create the appointment
var appointment = new Appointment(service);
appointment.Subject = appt.Subject;
appointment.Body = appt.Body;
appointment.Start = appt.Begin;
appointment.End = appt.End;
appointment.LegacyFreeBusyStatus = appt.Busy ? LegacyFreeBusyStatus.Busy : LegacyFreeBusyStatus.Free;
return appointment;
}
}
function void Main()
{
var appt = new MyAppointment()
{
Start = DateTime.Now(),
End = DateTime.Now().AddMinutes(30),
Subject = "Sample 1",
Body = "Sample 1 Body",
Busy = true
};
CreateAppt("mailboxid", appt);
}
public class MyAppointment
{
public int Id { get; set; }
public DateTime Start { get; set; }
public DateTime End { get; set; }
public string Subject { get; set; }
public string Body { get; set; }
public string Busy { get; set; }
public string ExchangeId { get; set; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment