문제

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:

  • Create an Exchange service
  • Use credentials of service account
  • AutodiscoverUrl()
  • Create CalenderFolder, CalenderView und retrieve appointments.
  • ?

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(@"svc_account@domain.com", 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.

도움이 되었습니까?

해결책

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 = @"impy@domain.com";

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, @"CAR1@domain.com");

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

다른 팁

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 = "user@mydomain.com";

var mailbox = new Mailbox(emailAddress);
var folderId = new FolderId(WellKnownFolderName.Calendar, mailbox);
var calendar = CalendarFolder.Bind(service, 
                                   folderId, 
                                   BasePropertySet.FirstClassProperties);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top