2017-02-25 66 views
0

我有一个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,但现在不在桌面上。

我觉得我失去了一些东西非常基本的...

+0

您是在PC上使用Outlook还是日历应用程序? –

+0

个人电脑使用Outlook,移动使用标准日历应用程序。两者都同步到相同的Outlook交换帐户。我的UWP应用程序适用于两者,它只是在PC上,它不会读取IReadOnlyList 列表中的任何约会。我通过做一个var ct = new MessageDialog(appointmentments.Count.ToString())来检查它。等待ct.ShowAsync(); – Geo

+0

AppointmentStore不是与交换机通信的API,而是与系统上的数据通信的API。我不认为outlook使用这个api将交换数据放在系统中,比如日历应用。所以有两个解决方案:配置日历应用程序以获取您的电脑上的数据或使用交换API获取数据 –

回答

0

的AppointmentStore心不是与交换通信的API,但与系统上的数据。我不认为outlook使用这个api将交换数据放在系统中,比如日历应用。因此,有两种解决方案:配置日历应用程序以获取个人电脑上的数据或使用交换API获取数据

+0

它肯定会帮助如果您解释_how_以配置日历应用程序以获取数据。没有一个建议是没用的。 –

相关问题