我想通过他的电子邮件获得与我的同事在某个日期范围内的所有约会。我可以通过outlook访问他的日历。我只想知道他是否预约了“免费”,“忙碌”或“OOF”。该代码使用“完整详细信息”权限,但不适用于“忙/闲时间,主题,位置”权限级别。
我的同事不应将权限级别更改为“完整详细信息”。它应该保持“忙/闲时间,主题,位置”,如下所示:
我有以下代码:
private static void GetAllCalendarItems()
{
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP1);
service.UseDefaultCredentials = true;
service.Url = new Uri("https://example.com/EWS/Exchange.asmx");
FolderId cfolderid = new FolderId(WellKnownFolderName.Calendar, "coworker@mexample.com");
Folder TargetFolder = Folder.Bind(service, cfolderid);
CalendarFolder calendar = CalendarFolder.Bind(service, cfolderid);
CalendarView cView = new CalendarView(DateTime.Now, DateTime.Now.AddDays(30), 5);
cView.PropertySet = new PropertySet(AppointmentSchema.Subject, AppointmentSchema.LegacyFreeBusyStatus);
FindItemsResults<Appointment> appointments = null;
try
{
appointments = calendar.FindAppointments(cView);
}
catch (ServiceResponseException ex)
{
Debug.WriteLine("Error code: " + ex.ErrorCode);
Debug.WriteLine("Error message: " + ex.Message);
Debug.WriteLine("Response: " + ex.Response);
}
foreach (Appointment a in appointments)
{
Debug.Write("Subject: " + a.Subject.ToString() + "\t\t\t");
Debug.Write("Status: " + a.LegacyFreeBusyStatus.ToString() + "\t\t\t");
Debug.WriteLine("");
}
}
此代码适用于我的电子邮件。但不是我同事的那个。我的try-catch-block中出现以下异常:
Exception thrown: 'Microsoft.Exchange.WebServices.Data.ServiceResponseException' in Microsoft.Exchange.WebServices.dll
Error code: ErrorAccessDenied
Error message: Access is denied. Check credentials and try again.
Response: Microsoft.Exchange.WebServices.Data.FindItemResponse`1[Microsoft.Exchange.WebServices.Data.Appointment]
我可以使用给定的权限访问他的日历,因为我可以在outlook中查看他的约会,那么如何通过他的电子邮件从我的同事处获得具有状态的约会?
答案 0 :(得分:2)
如果这适用于Reviewer权限而不是Free / Busy设置,我只能假定您需要Reviewer权限级别来阅读日历。
获取忙/闲时间的替代方法是使用ExchangeService.GetUserAvailability
请参阅以下资源:
https://msdn.microsoft.com/en-us/library/office/dn643673(v=exchg.150).aspx https://msdn.microsoft.com/en-us/library/microsoft.exchange.webservices.data.exchangeservice.getuseravailability(v=exchg.80).aspx
以上链接中的代码将来会中断:
// Create a collection of attendees.
List<AttendeeInfo> attendees = new List<AttendeeInfo>();
attendees.Add(new AttendeeInfo()
{
SmtpAddress = "mack@contoso.com",
AttendeeType = MeetingAttendeeType.Organizer
});
attendees.Add(new AttendeeInfo()
{
SmtpAddress = "sadie@contoso.com",
AttendeeType = MeetingAttendeeType.Required
});
// Specify options to request free/busy information and suggested meeting times.
AvailabilityOptions availabilityOptions = new AvailabilityOptions();
availabilityOptions.GoodSuggestionThreshold = 49;
availabilityOptions.MaximumNonWorkHoursSuggestionsPerDay = 0;
availabilityOptions.MaximumSuggestionsPerDay = 2;
// Note that 60 minutes is the default value for MeetingDuration, but setting it explicitly for demonstration purposes.
availabilityOptions.MeetingDuration = 60;
availabilityOptions.MinimumSuggestionQuality = SuggestionQuality.Good;
availabilityOptions.DetailedSuggestionsWindow = new TimeWindow(DateTime.Now.AddDays(1), DateTime.Now.AddDays(2));
availabilityOptions.RequestedFreeBusyView = FreeBusyViewType.FreeBusy;
// Return free/busy information and a set of suggested meeting times.
// This method results in a GetUserAvailabilityRequest call to EWS.
GetUserAvailabilityResults results = service.GetUserAvailability(attendees,
availabilityOptions.DetailedSuggestionsWindow,
AvailabilityData.FreeBusyAndSuggestions,
availabilityOptions);
答案 1 :(得分:0)
您的编译器是否在此行上抛出错误?
FolderId cfolderid = new FolderId(WellKnownFolderName.Calendar, "coworker@mexample.com");
应该是这样的:
FolderId cfolderid = new FolderId(WellKnownFolderName.Calendar, new Mailbox("coworker@mexample.com"));
请注意,只使用CalendarView
作为您的日期范围,您就是在浪费时间。请尝试使用SearchFilter
代替或另外使用。