我有一個UWP程序,它基本上檢索約會列表,然後過濾它們以生成報告。C#UWP AppointmentStore.FindAppointmentsAsync不能在PC上工作
我使用的AppointmentManager.RequestStoreAsync和AppointmentStore.FindAppointmentsAsync按How to retrieve appointments in UWP from a Windows 10 calendar using C#
我所遇到的問題是,它工作正常,在Windows 10 Mobile設備上,而不是在Windows 10計算機上。他們都同步到相同的日曆。
我的代碼:
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代碼仍然能正常工作的電腦上。 (但它從來沒有在移動中實現)
代碼:
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);
看來,當部署到PC,而我現有Outlook.Items(WPF碼)IReadOnlyList總是空的正常工作。
如上所述,該代碼在手機上正常工作,這就是爲什麼我本質上想要升級到UWP,但現在不在桌面上。
我覺得我失去了一些東西非常基本的...
您是在PC上使用Outlook還是日曆應用程序? –
個人電腦使用Outlook,移動使用標準日曆應用程序。兩者都同步到相同的Outlook交換帳戶。我的UWP應用程序適用於兩者,它只是在PC上,它不會讀取IReadOnlyList列表中的任何約會。我通過做一個var ct = new MessageDialog(appointmentments.Count.ToString())來檢查它。等待ct.ShowAsync(); –
Geo
AppointmentStore不是與交換機通信的API,而是與系統上的數據通信的API。我不認爲outlook使用這個api將交換數據放在系統中,比如日曆應用。所以有兩個解決方案:配置日曆應用程序以獲取您的電腦上的數據或使用交換API獲取數據 –