2011-11-07 29 views
3

我試圖在周範圍內的Outlook中獲取所有約會,但不會再出現約會約會。Outlook過濾項目 - 獲取所有在一週範圍內的定期約會

下面是代碼:

var outlook = new Microsoft.Office.Interop.Outlook.Application(); 
    var calendar = outlook.Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar); 
    calendar.Items.IncludeRecurrences = true; 

    string filter = String.Format("[Start] >= {0} And [End] < {1}", 
      DateTime.Now.Date.ToString("ddddd h:nn AMPM"), 
      DateTime.Now.Date.AddDays(5).ToString("ddddd h:nn AMPM")); 
    Outlook.AppointmentItem appointment; 
    foreach (var item in calendar.Items.Restrict(filter)) 
    { 
     appointment = item as Outlook.AppointmentItem; 
     if (appointment != null) 
     { 
      MessageBox.Show(appointment.Start.ToString()); 
     } 
    } 

我如何獲得所有被顯示在Outlook一週範圍內定期約會?

回答

5

你必須使用recurrence pattern 將這個您的循環中:

 if (item.IsRecurring) 
     { 
      Microsoft.Office.Interop.Outlook.RecurrencePattern rp = item.GetRecurrencePattern(); 
      DateTime first = new DateTime(2011, 11, 7, item.Start.Hour, item.Start.Minute, 0); 
      DateTime last = new DateTime(2011, 12, 1); 
      Microsoft.Office.Interop.Outlook.AppointmentItem recur = null; 



      for (DateTime cur = first; cur <= last; cur = cur.AddDays(1)) 
      { 
        recur = rp.GetOccurrence(cur); 
        Console.WriteLine(cur.ToLongDateString()); 
      } 
     } 

看到this 更多信息

+1

那除非我試圖讓一天預約工作太棒了它沒有安排我有一個例外。我已經包裝了recur = rp.GetOccurrence(cur);嘗試趕上,繼續,並非常感謝! – Daryl

相關問題