创建每12年重复的Outlook约会

时间:2020-08-29 10:16:00

标签: c# outlook

尝试每隔12年重复创建Outlook约会时遇到问题。如以下代码段中所示抛出异常:

var oa = Application.CreateItem(Outlook.OlItemType.olAppointmentItem) as Outlook.AppointmentItem;
oa.Subject = "Test";
oa.Start = new DateTime(2009, 06, 12);
oa.End = new DateTime(2009, 06, 13);
oa.AllDayEvent = true;
oa.ReminderSet = false;
var rp = oa.GetRecurrencePattern();
rp.RecurrenceType = Outlook.OlRecurrenceType.olRecursYearly;
rp.StartTime = DateTime.Parse("2009-06-12");
rp.PatternStartDate = DateTime.Parse("2009-06-12");
rp.EndTime = DateTime.Parse("2009-06-13");
try
{
   rp.Interval = 12 * 12;  //throws exception
}
catch (COMException ex)
{
//Exception is:
//Exception Type: System.Runtime.InteropServices.COMException
//Error Code: A5120009
//Exception: The recurrence pattern is not valid.
//Source: Microsoft Outlook
//Stack Trace:
//   at Microsoft.Office.Interop.Outlook.RecurrencePattern.set_Interval(Int32 Interval)
}

几点:

  1. 我认为Microsoft文档在此处不正确:

当RecurrenceType设置为olRecursYearNth或olRecursYear时,“间隔”属性指示两次出现之间的年数。例如,间隔等于1表示每年重复发生一次,间隔等于2表示每年重复发生一次,依此类推。

我的实验表明,对于olRecursYear,您需要指定以月为单位的间隔,因此,要想每2年实现一次复发,需要在间隔字段中输入24。

  1. 可以在Outlook GUI中指定每12年重复一次,如果我在代码中检索到此类约会,则在“间隔”字段中将得到144(12 * 12)。问题是要使用C#代码从头开始创建此类约会。

Outlook API专家有任何帮助/指导吗?也许我误解了Microsoft文档中的某些内容?

感谢您的答复!

1 个答案:

答案 0 :(得分:0)

在Outlook 2013下进行了检查-与Outlook 2016和2019一样,RecurrencePattern.Interval期望并返回几个月而不是几年。

所以行为是一样的,只是文档是错误的。

相关问题