【发布时间】:2017-02-25 14:26:21
【问题描述】:
我有一个 UWP 程序,它主要检索约会列表,然后过滤它们以生成报告。
我正在按照How to retrieve appointments in UWP from a Windows 10 calendar using C# 使用 AppointmentManager.RequestStoreAsync 和 AppointmentStore.FindAppointmentsAsync
我遇到的问题是它在 Windows 10 Mobile 设备上运行良好,但在 Windows 10 PC 上却不行。它们都同步到相同的日历。
我的代码:
AppointmentStore appointmentStore = await AppointmentManager.RequestStoreAsync(AppointmentStoreAccessType.AllCalendarsReadOnly);
DayOfWeek weekStart = DayOfWeek.Monday;
DateTimeOffset startingDate = DateTimeOffset.Now;
while (startingDate.DayOfWeek != weekStart)
startingDate = startingDate.AddDays(-1);
DateTimeOffset currentPayStart = startingDate.AddDays(-14);
var date = currentPayStart;
var timeZoneOffset = TimeZoneInfo.Local.GetUtcOffset(DateTime.Now);
var startTime = new DateTimeOffset(date.Year, date.Month, date.Day, 0, 0, 0, timeZoneOffset);
TimeSpan duration = TimeSpan.FromDays(7);
FindAppointmentsOptions options = new FindAppointmentsOptions();
options.MaxCount = 100;
options.FetchProperties.Add(AppointmentProperties.Subject);
options.FetchProperties.Add(AppointmentProperties.Location);
options.FetchProperties.Add(AppointmentProperties.AllDay);
options.FetchProperties.Add(AppointmentProperties.StartTime);
options.FetchProperties.Add(AppointmentProperties.Duration);
options.FetchProperties.Add(AppointmentProperties.Details);
options.FetchProperties.Add(AppointmentProperties.DetailsKind);
IReadOnlyList<Appointment> appointments = await appointmentStore.FindAppointmentsAsync(startTime, duration, options);
我有旧的 WPF 代码,在 PC 上仍然可以正常工作。 (但从未在手机上实现)
代码:
var outlookApp = new Outlook.Application();
var calFolder = outlookApp.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar) as Outlook.Folder;
DayOfWeek weekStart = DayOfWeek.Monday;
DateTime startingDate = DateTime.Today;
while (startingDate.DayOfWeek != weekStart)
startingDate = startingDate.AddDays(-1);
DateTime previousWeekStart = startingDate.AddDays(-7);
DateTime previousWeekEnd = startingDate.AddDays(0);
Outlook.Items rangeAppts = GetAppointmentsInRange(calFolder, previousWeekStart, previousWeekEnd);
似乎 IReadOnlyList 在部署到 PC 时始终为空,而我现有的 Outlook.Items(WPF 代码)工作正常。
如上所述,代码在移动设备上运行良好,这就是为什么我想升级到 UWP,但现在不在桌面上。
我觉得我错过了一些非常基本的东西......
【问题讨论】:
-
您是在 PC 上使用 Outlook 还是日历应用程序?
-
PC 使用 Outlook,手机使用标准日历应用。两者都同步到同一个 Outlook Exchange 帐户。我的 UWP 应用程序适用于两者,它只是在 PC 上,它不会将任何约会读入 IReadOnlyList
列表。我通过 var ct = new MessageDialog(appointments.Count.ToString()); 进行了检查。等待 ct.ShowAsync(); -
AppointmentStore 不是一个与 exchange 通信的 api,而是与系统上的数据通信。我认为 Outlook 不会像日历应用程序那样使用此 api 将交换中的数据放入系统中。所以有两种解决方案:配置日历应用程序以获取您电脑上的数据或使用交换 api 获取数据
-
我知道这将是一个基本的新手错误!我已经在 PC 上打开了日历应用程序并创建了有问题的交换帐户,现在一切正常。也解释了为什么手机应用部署只能看到前两周,这是应用限制,不是账户提供商限制。 [链接]support.office.com/en-us/article/…
标签: c# list calendar uwp appointment