最近开发一个outlook addin,要用到outllook 的calendar,其他有一个功能是新建立一个约会或会议时,这些约会或会议可能有同期性,因此在建立一个约会以后,则设定了固定周期的约会就会自动出现。
由于以前没有做过类似的开发,只是参照了MSDN写了一个创建约会的程序,但是怎么去让它循环这个问题,并不清楚。再看了Outlook.AppointmentItem这个类,发现里面有一个RecurrenceState属性,看上去只有它与Recurrence Appointment有关,但是再认真一看,这个是一个只读属性,不能设的,因此一时陷入困境,不知道怎么去办。
后来上网上查了一下,感觉也没什么结果。
后来,就随便试了一下,程序如下,就可以解决了。希望对大家有所帮助。
private void CreateAppointment()
{
Outlook.AppointmentItem pAppointmentitem = null;
Redemption.SafeAppointmentItem rAppointmentItem = null;
rAppointmentItem = new Redemption.SafeAppointmentItemClass();
Outlook.RecurrencePattern iRec = null;
pAppointmentitem=(Outlook.AppointmentItem) this.OutlookApplication.CreateItem(Outlook.OlItemType.olAppointmentItem);
rAppointmentItem.Item = pAppointmentitem;
pAppointmentitem.Subject = "Test Daily";
pAppointmentitem.Start = DateTime.Parse("2007-12-16 08:00:00.000");
pAppointmentitem.End = DateTime.Parse("2007-12-16 08:00:00.000").AddMinutes(30);
pAppointmentitem.AllDayEvent = false;
pAppointmentitem.Sensitivity = Outlook.OlSensitivity.olPrivate;
rAppointmentItem.RTFBody = "Test outlook appointment";
pAppointmentitem.ReminderSet = true;
pAppointmentitem.ReminderMinutesBeforeStart = 5;
pAppointmentitem.ReminderPlaySound = false;
iRec = pAppointmentitem.GetRecurrencePattern();
iRec.Duration = 30;
iRec.StartTime = DateTime.Parse("2007-12-16 08:00:00.000");
iRec.RecurrenceType = Outlook.OlRecurrenceType.olRecursDaily;
iRec.Interval = 1;
iRec.NoEndDate = false;
iRec.PatternEndDate = DateTime.Parse("2007-12-16 08:00:00.000").AddDays(10);
iRec.Occurrences = 10;
iRec.PatternStartDate = DateTime.Parse("2007-12-16 08:00:00.000");
pAppointmentitem.Categories = "";
pAppointmentitem.Save();
}