Marco
Marco

Reputation: 23945

How to retrieve public calendars from EWS?

We are managing the reservations for our car pool via exchange. Every car has a calender on which you can insert an appointment with the car, for when you want to use it.

My task is to retrieve every car's calender and every appointment in it, but I am stuck on how to make the right call via EWS.

My steps are as following:

Right now my problem is located at "retrieve appointments" because I can only access my own calender with its WellKnownFolders.

How can I access someone else public calanders and retrieve their appointments?

This is the code I am working with so far: (gathered from http://msdn.microsoft.com/en-us/library/office/dn439786(v=exchg.80).aspx)

ServicePointManager.ServerCertificateValidationCallback = CertificateValidationCallBack;

ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP1);
service.Credentials = new WebCredentials(@"domain\svc_account", @"Dummypassword");
service.UseDefaultCredentials = false;
service.TraceEnabled = true;
service.TraceFlags = TraceFlags.All;
service.AutodiscoverUrl(@"[email protected]", RedirectionUrlValidationCallback);

DateTime startTime = DateTime.Now;
DateTime endTime = DateTime.Now.AddDays(10);
int num_appts = 10;

CalendarFolder calFolder = CalendarFolder.Bind(service, WellKnownFolderName.Calendar, new PropertySet());
CalendarView calView = new CalendarView(startTime, endTime, 10);
calView.PropertySet = new PropertySet(AppointmentSchema.Subject, AppointmentSchema.Start, AppointmentSchema.End);

FindItemsResults<Appointment> appointments = calFolder.FindAppointments(calView);

foreach (Appointment a in appointments)
{
    //Do stuff later on...
}

Again: This works well for appointments in my calender. I can't find the parts in the MSDN on how to access someone else data.

Upvotes: 1

Views: 2033

Answers (2)

jeroenh
jeroenh

Reputation: 26792

Given the service user has read access to the given user's calendar, you can do something like this:

// this is the user whose calendar you want to access
var emailAddress = "[email protected]";

var mailbox = new Mailbox(emailAddress);
var folderId = new FolderId(WellKnownFolderName.Calendar, mailbox);
var calendar = CalendarFolder.Bind(service, 
                                   folderId, 
                                   BasePropertySet.FirstClassProperties);

Upvotes: 2

Brett McKenzie
Brett McKenzie

Reputation: 605

Have a look at Exchange Impersonation.

You can have a specific user account impersonate another user account and access their details without the need for their username and password. This should work on resource calendars as well.

string impName = @"impy";
string impPassword = @"password";
string impDomain = @"domain";
string impEmail = @"[email protected]";

ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010);
service.Credentials = new NetworkCredential(impName, impPassword, impDomain);
service.AutodiscoverUrl(impEmail);

// This will work as if you are that car.
service.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, @"[email protected]");

More references: http://msdn.microsoft.com/en-us/library/dd633680(v=exchg.80).aspx

Upvotes: 3

Related Questions