在展望VSTO中,无论如何都要获得定期约会的最后日期?

时间:2015-11-10 05:12:45

标签: outlook vsto

我有一个VSTO应用程序,我正在试图找出如何引用日历定期约会并捕获系列中的最后一个日期

我首先搜索日期范围ideone demo中的项目,使用:

Outlook.Folder calFolder =
    Application.Session.GetDefaultFolder(
    Outlook.OlDefaultFolders.olFolderCalendar)
    as Outlook.Folder;
DateTime start = DateTime.Now;
DateTime end = start.AddDays(5);
Outlook.Items rangeAppts = GetAppointmentsInRange(calFolder, start, end);
if (rangeAppts != null)
{
    foreach (Outlook.AppointmentItem appt in rangeAppts)
    {
        Debug.WriteLine("Subject: " + appt.Subject 
            + " Start: " + appt.Start.ToString("g"));
    }
}


private Outlook.Items GetAppointmentsInRange(
Outlook.Folder folder, DateTime startTime, DateTime endTime)
 {
string filter = "[Start] >= '"
    + startTime.ToString("g")
    + "' AND [End] <= '"
    + endTime.ToString("g") + "'";
Debug.WriteLine(filter);
try
{
    Outlook.Items calItems = folder.Items;
    calItems.IncludeRecurrences = true;
    calItems.Sort("[Start]", Type.Missing);
    Outlook.Items restrictItems = calItems.Restrict(filter);
    if (restrictItems.Count > 0)
    {
        return restrictItems;
    }
    else
    {
        return null;
    }
}
catch { return null; }

}

但我无法弄清楚如何查看定期规则以计算约会的最后结束日期。这在Outlook VSTO中是否可行。

1 个答案:

答案 0 :(得分:1)

从搜索结果中获取对单个AppointmentItem的引用,然后调用http://phantomjs.org/api/webpage/handler/on-callback.html以获取RecurrencePattern对象。然后,您可以评估.PatternEndDate以查找系列中最后一个事件的日期,然后使用RecurrencePattern.GetOccurrence(date)获取对该特定约会的引用。

相关问题