Outlook Filter Elements. Get all recurring appointments in the weekly range.

I try to get all appointments in Outlook over a range of weeks, but repeat appointments are not displayed.

Here is the code:

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()); } } 

How to get all recurring appointments displayed in Outlook for a weekly range?

+3
source share
1 answer

You should use a repeat pattern. Put this inside your loop:

  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()); } } 

see for more information

+5
source

Source: https://habr.com/ru/post/924013/


All Articles