在 outlook VSTO 中,是否可以获取定期约会的最后日期?
In outlook VSTO, is there anyway to get the last date of a recurring appointment?
我有一个 VSTO 应用程序,我正在尝试弄清楚如何获取对日历定期约会的引用并捕获系列中的最后一个日期
我首先搜索日期范围 which i got from here 中的项目,使用:
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 中是否可行。
从搜索结果中获取对单个 AppointmentItem 的引用,然后调用 GetRecurrencePattern 获取 RecurrencePattern 对象。然后,您可以评估 .PatternEndDate 以查找系列中最后一个事件的日期,然后使用 RecurrencePattern.GetOccurrence(date) 获取对该特定约会的引用。
我有一个 VSTO 应用程序,我正在尝试弄清楚如何获取对日历定期约会的引用并捕获系列中的最后一个日期
我首先搜索日期范围 which i got from here 中的项目,使用:
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 中是否可行。
从搜索结果中获取对单个 AppointmentItem 的引用,然后调用 GetRecurrencePattern 获取 RecurrencePattern 对象。然后,您可以评估 .PatternEndDate 以查找系列中最后一个事件的日期,然后使用 RecurrencePattern.GetOccurrence(date) 获取对该特定约会的引用。