如何使用ews在office 365中查找可用性日历会议?

时间:2016-06-16 12:53:29

标签: c# asp.net-mvc exchangewebservices

您好,
我需要在办公室365中获得特定的用户可用性计时,但我在访问日历事件时收到此错误“SMTP地址没有与之关联的邮箱”,我在下面给出了我的代码,任何一个帮我解决这个错误。

        string stat = "06/18/2016 11:00:00 AM";
        string end = "06/18/2016 2:00:00 PM";

        DateTime start = Convert.ToDateTime(stat);
        DateTime endt = Convert.ToDateTime(end);

        string mailBox = "XXXXXXXX@XXXX.com";

        ExchangeService esvc = new ExchangeService(ExchangeVersion.Exchange2010);
        esvc.Credentials = new WebCredentials("XXXXXXXXX@XXXXXX.com", "XXXXX", "XXXX.com");
        esvc.Url = new Uri("https://XXXXXX.com/ews/Exchange.asmx");

        FolderId shareFolderId = new FolderId(WellKnownFolderName.Calendar, "Calendar");
        // The following line throws an exception.
        CalendarFolder.Bind(esvc, shareFolderId);


        FolderId parkplatzCalendarId = new FolderId(WellKnownFolderName.Calendar, mailBox);

        CalendarFolder calendar = CalendarFolder.Bind(esvc, parkplatzCalendarId);

        CalendarView cView = new CalendarView(start, endt, int.MaxValue);

        cView.PropertySet = new PropertySet(AppointmentSchema.Subject, AppointmentSchema.Start, AppointmentSchema.End, AppointmentSchema.Duration, AppointmentSchema.LastModifiedName, AppointmentSchema.Organizer, AppointmentSchema.Categories);

        FindItemsResults<Appointment> appointments = calendar.FindAppointments(cView);

1 个答案:

答案 0 :(得分:0)

创建FolderId

时,参数“日历”没有意义
FolderId shareFolderId = new FolderId(WellKnownFolderName.Calendar, "Calendar");

相反,您应该将“日历”替换为用户的邮箱对象:

FolderId shareFolderId = new FolderId(WellKnownFolderName.Calendar, new Mailbox("user@domain.com"));