C#Outlook通过使用EWS公开其他用户的约会

时间:2015-10-06 13:22:09

标签: c# exchange-server outlook-addin exchangewebservices appointment

我目前正在尝试将Outlook中的用户日历(使用Exchange2013)的公共约会检索到稍后要显示的DataSet。
这是目前为止的相关代码:

ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2013);
service.AutodiscoverUrl("mail@mycompany.com", RedirectionCallback);
DateTime reportDate = dateTimePicker1.Value;
DateTime startDate = new DateTime(reportDate.Year, reportDate.Month, reportDate.Day, 0, 0, 1);
DateTime endDate = startDate.AddHours(23);
endDate = endDate.AddMinutes(59);
CalendarFolder calendar = CalendarFolder.Bind(service, new FolderId(WellKnownFolderName.Calendar, "somemail@mycompany.com"));
CalendarView cView = new CalendarView(startDate, endDate);
cView.PropertySet = new PropertySet(AppointmentSchema.Subject, AppointmentSchema.Start, AppointmentSchema.End, AppointmentSchema.Location);

// get appointment collection
FindItemsResults<Appointment> appointments = calendar.FindAppointments(cView);

// transfer to DataSet
DataSet1.Tables[0].Rows.Clear();
int i = 0;
foreach (Appointment a in appointments) {
    DataSet1.Tables[0].Rows.Add(
        i++.ToString(),
        a.Subject.ToString(),
        a.Start.ToString(),
        a.End.ToString(),
        a.Location.ToString());
}

中显示异常
  

CalendarFolder calendar = CalendarFolder.Bind(service,new FolderId(WellKnownFolderName.Calendar,&#34; somemail@mycompany.com"));

我在这里做错了什么想法?或者甚至还有其他方法可以解决我的问题?

1 个答案:

答案 0 :(得分:0)

您用来连接Exchange服务器的帐户没有权限读取somemail@mycompany.com的邮箱。尝试获取该帐户的超级用户权限。希望这很有用。