public static void Run()
{
// ExStart:MonthlyEndAfterNoccurrences
// The path to the File directory.
string dataDir = RunExamples.GetDataDir_Outlook();
TimeZone localZone = TimeZone.CurrentTimeZone;
TimeSpan ts = localZone.GetUtcOffset(DateTime.Now);
DateTime StartDate = new DateTime(2015, 7, 16);
StartDate = StartDate.Add(ts);
DateTime DueDate = new DateTime(2015, 7, 16);
DateTime endByDate = new DateTime(2015, 12, 31);
DueDate = DueDate.Add(ts);
endByDate = endByDate.Add(ts);
MapiTask task = new MapiTask("This is test task", "Sample Body", StartDate, DueDate);
task.State = MapiTaskState.NotAssigned;
// Set the Monthly recurrence
var rec = new MapiCalendarMonthlyRecurrencePattern
{
Day = 15,
Period = 1,
PatternType = MapiCalendarRecurrencePatternType.Month,
EndType = MapiCalendarRecurrenceEndType.EndAfterNOccurrences,
OccurrenceCount = GetOccurrenceCount(StartDate, endByDate, "FREQ=MONTHLY;BYMONTHDAY=15;INTERVAL=1"),
WeekStartDay = DayOfWeek.Monday,
};
if (rec.OccurrenceCount == 0)
{
rec.OccurrenceCount = 1;
}
task.Recurrence = rec;
task.Save(dataDir + "Monthly_out.msg", TaskSaveFormat.Msg);
// ExEnd:MonthlyEndAfterNoccurrences
}