How to retrieve public calendars from EWS?

穿精又带淫゛_ 提交于 2019-12-24 14:02:16

问题


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.


回答1:


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




回答2:


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);


来源:https://stackoverflow.com/questions/20947788/how-to-retrieve-public-calendars-from-ews

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!