如何从特定日历(特定日期)获取所有项目.让我们说比如每周一晚上我有一个带有重复项目的日历.当我请求所有这样的项目时:
CalendarItems = CalendarFolder.Items; CalendarItems.IncludeRecurrences = true;
我只买1件......
是否有一种简单的方法可以从日历中获取所有项目(主要项目+派生项目)?在我的具体情况下,可以设置一个日期限制,但只是为了获得所有项目(我的经常性项目本身是时间限制的)很酷.
我正在使用Microsoft Outlook 12对象库(Microsoft.Office.Interop.Outlook).
我研究了文档,这是我的结果:我已经将一个月的时间限制硬编码,但这只是一个例子.
public void GetAllCalendarItems() { Microsoft.Office.Interop.Outlook.Application oApp = null; Microsoft.Office.Interop.Outlook.NameSpace mapiNamespace = null; Microsoft.Office.Interop.Outlook.MAPIFolder CalendarFolder = null; Microsoft.Office.Interop.Outlook.Items outlookCalendarItems = null; oApp = new Microsoft.Office.Interop.Outlook.Application(); mapiNamespace = oApp.GetNamespace("MAPI"); ; CalendarFolder = mapiNamespace.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderCalendar); outlookCalendarItems = CalendarFolder.Items; outlookCalendarItems.IncludeRecurrences = true; foreach (Microsoft.Office.Interop.Outlook.AppointmentItem item in outlookCalendarItems) { if (item.IsRecurring) { Microsoft.Office.Interop.Outlook.RecurrencePattern rp = item.GetRecurrencePattern(); DateTime first = new DateTime(2008, 8, 31, item.Start.Hour, item.Start.Minute, 0); DateTime last = new DateTime(2008, 10, 1); Microsoft.Office.Interop.Outlook.AppointmentItem recur = null; for (DateTime cur = first; cur <= last; cur = cur.AddDays(1)) { try { recur = rp.GetOccurrence(cur); MessageBox.Show(recur.Subject + " -> " + cur.ToLongDateString()); } catch { } } } else { MessageBox.Show(item.Subject + " -> " + item.Start.ToLongDateString()); } } }
我相信您必须限制或查找以获得定期约会,否则Outlook将不会扩展它们.此外,您必须在设置IncludeRecurrences 之前按开始排序.
我写了类似的代码,但后来发现了导出功能:
Application outlook; NameSpace OutlookNS; outlook = new ApplicationClass(); OutlookNS = outlook.GetNamespace("MAPI"); MAPIFolder f = OutlookNS.GetDefaultFolder(OlDefaultFolders.olFolderCalendar); CalendarSharing cs = f.GetCalendarExporter(); cs.CalendarDetail = OlCalendarDetail.olFullDetails; cs.StartDate = new DateTime(2011, 11, 1); cs.EndDate = new DateTime(2011, 12, 31); cs.SaveAsICal("c:\\temp\\cal.ics");