2014-06-11 44 views
0

基本上,始平在Office 365我的知識水平。獲取從Office365預約C#.NET

我想通過.Net Office 365 API調用從Office 365中取消預約,並在Windows應用網格中顯示它。

我正在使用代碼(如下)來拉約會;我已經收集來自網絡的代碼...

我已經成功,直到認證部分。我可以查看身份驗證成功的消息,並像FromTime的Office 365日曆屬性,Location等,但我不能接收數據。它返回System.Nullable DateTime Exception

namespace GetCal 
{ 
    public class CalendarAPISample 
    { 
     const string ExchangeResourceId = "https://outlook.office365.com"; 
     const string ExchangeServiceRoot = "https://outlook.office365.com/ews/odata"; 

     public static async Task<IOrderedEnumerable<IEvent>> GetCalendarEvents() 
     { 
      var client = await EnsureClientCreated(); 
      string fromdate = "01/01/2014"; 
      DateTime datet = Convert.ToDateTime(fromdate); 

      // Obtain calendar event data 
      var eventsResults = await(from i in client.Me.Events 
             where i.End >= datet //DateTimeOffset.UtcNow 
            select i).Take(10).ExecuteAsync(); 

      var events = eventsResults.CurrentPage.OrderBy(e => e.Start); 
      //return events.ToList().ConvertAll(new Converter(ent => ent)); 
      return events; 
     } 

     private static async Task<ExchangeClient> EnsureClientCreated() 
     { 
      Authenticator authenticator = new Authenticator(); 
      var authInfo = await authenticator.AuthenticateAsync(ExchangeResourceId); 

      return new ExchangeClient(new Uri(ExchangeServiceRoot), authInfo.GetAccessToken); 
     } 

     public static async Task SignOut() 
     { 
      await new Authenticator().LogoutAsync(); 
     } 

     public CalendarAPISample() 
     { 
      // TODO: Complete member initialization 
      try 
      { 
       // call the authenticator 
       var x = GetCalendarEvents();    

      } 
      catch (Exception ex) 
      { 
       Console.WriteLine(ex.Message); 
      } 
     } 
    } 
} 

EVENTS對象包含數據類型IEnumerable值。我想將IEnumerable轉換爲DataTable

+0

爲什麼你需要它是一個DataTable? – HaukurHaf

+0

數據集或數據表在網格中顯示約會 – user3729893

回答