การจัดการการเกิดซ้ำ

Contents
[ ]

ทำงานกับการทำซ้ำรายวัน

Aspose.Email รองรับการสร้างการทำซ้ำรายวันโดยใช้ MapiCalendarDailyRecurrencePattern. สามประเภทการสิ้นสุดการทำซ้ำของปฏิทิน Mapi ที่แตกต่างกันสามารถใช้ได้รวมถึง EndAfterNOccurrences, EndAfterDate และ NeverEnd. ส่วนนี้จะแสดงการสร้างรูปแบบการทำซ้ำรายวันที่ต่างกัน.

การทำซ้ำรายวันด้วยจำนวนการเกิด

ในชนิดการทำซ้ำนี้ จำนวนครั้งของการทำซ้ำต้องตั้งค่าพร้อมกับข้อมูลอื่น ๆ ดังต่อไปนี้:

  1. กำหนดวันที่เริ่ม, สิ้นสุด และกำหนดส่ง.
  2. สร้าง MapiTask.
  3. ตั้งค่าสถานะงานเป็น NotAssigned.
  4. สร้างอ็อบเจ็กต์การเกิดซ้ำรายวันโดยกำหนดคุณสมบัติเช่น PatternType, Period, WeekStartDay, EndType และ OccurenceCount.
  5. ตั้งค่า property MapiTask.Recurrence ให้เป็นอ็อบเจ็กต์การเกิดซ้ำรายวันนี้.
  6. บันทึกข้อความนี้ลงดิสก์.

โค้ดสแนปต่อไปนี้แสดงวิธีสร้างงานพร้อมประเภทการสิ้นสุดการเกิดซ้ำเป็น EndAfterNOccurrence.

// The path to the File directory.
string dataDir = RunExamples.GetDataDir_Outlook();

TimeZone localZone = TimeZone.CurrentTimeZone;
TimeSpan timeSpan = localZone.GetUtcOffset(DateTime.Now);
DateTime StartDate = new DateTime(2015, 7, 16);
StartDate = StartDate.Add(timeSpan);

DateTime DueDate = new DateTime(2015, 7, 16);
DateTime endByDate = new DateTime(2015, 8, 1);
DueDate = DueDate.Add(timeSpan);
endByDate = endByDate.Add(timeSpan);
 
MapiTask task = new MapiTask("This is test task", "Sample Body", StartDate, DueDate);
task.State = MapiTaskState.NotAssigned;

// Set the Daily recurrence
var rec = new MapiCalendarDailyRecurrencePattern
{
    PatternType = MapiCalendarRecurrencePatternType.Day,
    Period = 1,
    WeekStartDay = DayOfWeek.Sunday,
    EndType = MapiCalendarRecurrenceEndType.EndAfterNOccurrences,
    OccurrenceCount = GetOccurrenceCount(StartDate, endByDate, "FREQ=DAILY"),
};

if (rec.OccurrenceCount==0)
{
    rec.OccurrenceCount = 1;
}

task.Recurrence = rec;
task.Save(dataDir + "Daily_out.msg", TaskSaveFormat.Msg);

ฟังก์ชันต่อไปนี้สามารถใช้คำนวนจำนวนเหตุการณ์ระหว่างสองวันที่:

private static uint GetOccurrenceCount(DateTime start, DateTime endBy, string rrule)
{
    CalendarRecurrence pattern = new CalendarRecurrence(string.Format("DTSTART:{0}\r\nRRULE:{1}", start.ToString("yyyyMMdd"), rrule));
    DateCollection dates = pattern.GenerateOccurrences(start, endBy);
    return (uint)dates.Count;
}

ตั้งค่าจำนวนครั้งของการทำซ้ำ

โค้ดตัวอย่างต่อไปนี้จะแสดงวิธีตั้งค่าค่าจำนวนครั้งของการทำซ้ำ.

// Set the Daily recurrence
var record = new MapiCalendarDailyRecurrencePattern
{
    PatternType = MapiCalendarRecurrencePatternType.Day,
    Period = 1,
    WeekStartDay = DayOfWeek.Sunday,
    EndType = MapiCalendarRecurrenceEndType.EndAfterNOccurrences,
    OccurrenceCount = 5,
};
task.Recurrence = record;

การทำซ้ำรายวัน: ชนิด EndAfterDate

"End By" ตัวเลือกใน Mapi Task จะทำได้โดยการตั้งค่า property OccurrenceCount ที่คำนวณโดยฟังก์ชัน GetOccurrenceCount() ฟังก์ชันนี้รับค่า start date , end date และสตริง RRULE.

การทำซ้ำรายวัน: การตั้งค่าค่า Every Day

โค้ดตัวอย่างต่อไปนี้จะแสดงวิธีตั้งค่าค่า period เป็น 1 และค่า INTERVAL เป็น 1 ในสตริง RRULE ด้วย.

// Set the Daily recurrence
var record = new MapiCalendarDailyRecurrencePattern
{
    PatternType = MapiCalendarRecurrencePatternType.Day,
    Period = 1,
    EndType = MapiCalendarRecurrenceEndType.EndAfterDate,
    OccurrenceCount = GetOccurrenceCount(StartDate, endByDate, "FREQ=DAILY;INTERVAL=1"),
    EndDate = endByDate
};

ค่าของ Every Day สามารถตั้งค่าเป็นค่าที่เหมาะสมใด ๆ ตามที่แสดงในตัวอย่างต่อไปนี้:


// Set the Daily recurrence
var record = new MapiCalendarDailyRecurrencePattern
{
	PatternType = MapiCalendarRecurrencePatternType.Day,
	Period = 2,
	EndType = MapiCalendarRecurrenceEndType.EndAfterDate,
	OccurrenceCount = GetOccurrenceCount(StartDate, endByDate, "FREQ=DAILY;INTERVAL=2"),
};

การทำซ้ำรายวัน: ชนิด NeverEnd

ประเภทการสิ้นสุดสามารถตั้งค่าโดยใช้ MapiCalendarRecurrenceEndType.NeverEnd. Period หรือ INTERVAL สามารถตั้งค่าเป็นค่าที่ต้องการเช่น 1 ในตัวอย่างต่อไปนี้.

// Set the Daily recurrence
var record = new MapiCalendarDailyRecurrencePattern
{
    PatternType = MapiCalendarRecurrencePatternType.Day,
    Period = 1,
    EndType = MapiCalendarRecurrenceEndType.NeverEnd,
};

ทำงานกับการทำซ้ำรายสัปดาห์

Aspose.Email มีคุณลักษณะที่หลากหลายสำหรับการสร้างการทำซ้ำรายสัปดาห์โดยใช้ MapiCalendarWeeklyRecurrencePattern. สามประเภทการสิ้นสุดการทำซ้ำของปฏิทิน Mapi ที่แตกต่างกันสามารถใช้ได้รวมถึง EndAfterNOccurrences, EndAfterDate และ NeverEnd. ส่วนนี้จะแสดงการสร้างรูปแบบการทำซ้ำรายสัปดาห์ที่หลากหลาย.

การทำซ้ำรายสัปดาห์: ชนิด EndAfterNOccurrences

ในชนิดการทำซ้ำนี้ จำนวนครั้งของการทำซ้ำต้องตั้งค่าพร้อมกับข้อมูลอื่น ๆ ดังต่อไปนี้:

  1. กำหนดวันที่เริ่ม, สิ้นสุด และกำหนดส่ง.
  2. สร้าง MapiTask.
  3. ตั้งค่าสถานะงานเป็น NotAssigned.
  4. สร้างอ็อบเจกต์การทำซ้ำรายสัปดาห์โดยตั้งค่า property เช่น PatternType, Period, WeekStartDay, EndType และ OccurenceCount.
  5. ตั้งค่า property MapiTask.Recurrence ให้เป็นอ็อบเจกต์การทำซ้ำรายสัปดาห์นี้.
  6. บันทึกข้อความนี้ลงดิสก์.

โค้ดตัวอย่างต่อไปนี้แสดงวิธีสร้างงานโดยตั้งค่าประเภทการสิ้นสุดการทำซ้ำเป็น EndAfterNOccurrence.

// 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, 9, 1);
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 weekly recurrence
var rec = new MapiCalendarWeeklyRecurrencePattern
{
    EndType = MapiCalendarRecurrenceEndType.EndAfterNOccurrences,
    PatternType = MapiCalendarRecurrencePatternType.Week,
    Period = 1,
    WeekStartDay = DayOfWeek.Sunday,
    DayOfWeek = MapiCalendarDayOfWeek.Friday,
    OccurrenceCount = GetOccurrenceCount(StartDate, endByDate, "FREQ=WEEKLY;BYDAY=FR"),
};

if (rec.OccurrenceCount == 0)
{
    rec.OccurrenceCount = 1;
}

task.Recurrence = rec;
task.Save(dataDir + "Weekly_out.msg", TaskSaveFormat.Msg);

ฟังก์ชันต่อไปนี้สามารถใช้คำนวนจำนวนเหตุการณ์ระหว่างสองวันที่:

private static uint GetOccurrenceCount(DateTime start, DateTime endBy, string rrule)
{            
    CalendarRecurrence pattern = new CalendarRecurrence(string.Format("DTSTART:{0}\r\nRRULE:{1}", start.ToString("yyyyMMdd"),rrule));            
    DateCollection dates = pattern.GenerateOccurrences(start, endBy);            
    return (uint)dates.Count;
}

การเลือกหลายวันในสัปดาห์

โค้ดตัวอย่างต่อไปนี้จะแสดงวิธีเลือกหลายวันในสัปดาห์.

// Set the weekly recurrence
var rec = new MapiCalendarWeeklyRecurrencePattern
{
    EndType = MapiCalendarRecurrenceEndType.EndAfterNOccurrences,
    PatternType = MapiCalendarRecurrencePatternType.Week,
    Period = 1,
    WeekStartDay = DayOfWeek.Sunday,
    DayOfWeek = MapiCalendarDayOfWeek.Friday | MapiCalendarDayOfWeek.Monday,
    OccurrenceCount = GetOccurrenceCount(StartDate, endByDate, "FREQ=WEEKLY;BYDAY=FR,MO"),
};

การเลือกหลายวันในสัปดาห์และการตั้งค่าช่วงเวลา

โค้ดตัวอย่างต่อไปนี้จะแสดงวิธีเลือกหลายวันในสัปดาห์และตั้งค่าช่วงเวลา.

// Set the weekly recurrence
var rec = new MapiCalendarWeeklyRecurrencePattern
{
    EndType = MapiCalendarRecurrenceEndType.EndAfterNOccurrences,
    PatternType = MapiCalendarRecurrencePatternType.Week,
    Period = 2,
    WeekStartDay = DayOfWeek.Sunday,
    DayOfWeek = MapiCalendarDayOfWeek.Friday | MapiCalendarDayOfWeek.Monday,
    OccurrenceCount = GetOccurrenceCount(StartDate, endByDate, "FREQ=WEEKLY;BYDAY=FR,MO;INTERVAL=2"),
};

การทำซ้ำรายสัปดาห์: ชนิด EndAfterDate

"End By" ตัวเลือกใน Mapi Task จะทำได้โดยการตั้งค่า property OccurrenceCount ที่คำนวณโดยฟังก์ชัน GetOccurrenceCount() ฟังก์ชันนี้รับค่า start date , end date และสตริง RRULE.

การทำซ้ำรายสัปดาห์: การตั้งค่าค่า Every Day

โค้ดตัวอย่างต่อไปนี้จะแสดงวิธีตั้งค่าค่า period เป็น 1 และค่า INTERVAL เป็น 1 ในสตริง RRULE ด้วย.

// Set the weekly recurrence
var rec = new MapiCalendarWeeklyRecurrencePattern
{
    EndType = MapiCalendarRecurrenceEndType.EndAfterDate,
    PatternType = MapiCalendarRecurrencePatternType.Week,
    Period = 1,
    WeekStartDay = DayOfWeek.Sunday,
    DayOfWeek = MapiCalendarDayOfWeek.Friday,
    EndDate = endByDate,
    OccurrenceCount = GetOccurrenceCount(StartDate, endByDate, "FREQ=WEEKLY;BYDAY=FR;INTERVAL=1"),
};

ค่าของ Every Day สามารถตั้งค่าเป็นค่าที่เหมาะสมใด ๆ และสามารถเลือกหลายวันได้ตามที่แสดงในตัวอย่างต่อไปนี้:

var record = new MapiCalendarWeeklyRecurrencePattern
{
    EndType = MapiCalendarRecurrenceEndType.EndAfterDate,
    PatternType = MapiCalendarRecurrencePatternType.Week,
    Period = 2,
    WeekStartDay = DayOfWeek.Sunday,
    EndDate = endByDate,
    DayOfWeek = MapiCalendarDayOfWeek.Friday | MapiCalendarDayOfWeek.Monday,
    OccurrenceCount = GetOccurrenceCount(StartDate, endByDate, "FREQ=WEEKLY;BYDAY=FR,MO;INTERVAL=2"),
};

การทำซ้ำรายสัปดาห์: ชนิด NeverEnd

ประเภทการสิ้นสุดสามารถตั้งค่าโดยใช้ MapiCalendarRecurrenceEndType.NeverEnd. Period หรือ INTERVAL สามารถตั้งค่าเป็นค่าที่ต้องการเช่น 1 ในตัวอย่างต่อไปนี้.

// Set the weekly recurrence
var recurrence = new MapiCalendarWeeklyRecurrencePattern
{
    EndType = MapiCalendarRecurrenceEndType.NeverEnd,
    PatternType = MapiCalendarRecurrencePatternType.Week,
    Period = 1,
    WeekStartDay = DayOfWeek.Sunday,
    DayOfWeek = MapiCalendarDayOfWeek.Friday,
    OccurrenceCount = GetOccurrenceCount(StartDate, endByDate, "FREQ=WEEKLY;BYDAY=FR"),
};

ทำงานกับการทำซ้ำรายเดือน

Aspose.Email รองรับการสร้างการทำซ้ำรายเดือนโดยใช้ MapiCalendarMonthlyRecurrencePattern. สามประเภทการสิ้นสุดการทำซ้ำของปฏิทิน Mapi ที่แตกต่างกันสามารถใช้ได้รวมถึง EndAfterNOccurrences, EndAfterDate และ NeverEnd. ส่วนนี้จะแสดงการสร้างรูปแบบการทำซ้ำรายเดือนที่หลากหลาย.

การทำซ้ำรายเดือน: ชนิด EndAfterNOccurrences

ในชนิดการทำซ้ำนี้ จำนวนครั้งของการทำซ้ำต้องตั้งค่าพร้อมกับข้อมูลอื่น ๆ ดังต่อไปนี้:

  1. กำหนดวันที่เริ่ม, สิ้นสุด และกำหนดส่ง.
  2. สร้าง MapiTask.
  3. ตั้งค่าสถานะงานเป็น NotAssigned.
  4. สร้างอ็อบเจกต์การทำซ้ำรายเดือนโดยตั้งค่า property เช่น PatternType, Period, WeekStartDay, EndType และ OccurenceCount.
  5. ตั้งค่า property MapiTask.Recurrence ให้เป็นอ็อบเจกต์การทำซ้ำรายเดือนนี้.
  6. บันทึกข้อความนี้ลงดิสก์.

โค้ดตัวอย่างต่อไปนี้แสดงวิธีสร้างงานโดยตั้งค่าประเภทการสิ้นสุดการทำซ้ำเป็น EndAfterNOccurrence.

// 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);

ฟังก์ชันต่อไปนี้สามารถใช้คำนวนจำนวนเหตุการณ์ระหว่างสองวันที่:

private static uint GetOccurrenceCount(DateTime start, DateTime endBy, string rrule)
{
    CalendarRecurrence pattern = new CalendarRecurrence(string.Format("DTSTART:{0}\r\nRRULE:{1}", start.ToString("yyyyMMdd"), rrule));
    DateCollection dates = pattern.GenerateOccurrences(start, endBy);       
    return (uint)dates.Count;
}

ตั้งค่าจำนวนการเกิดที่คงที่

โค้ด snippet ต่อไปนี้แสดงวิธีตั้งค่าจำนวนการเกิดที่คงที่.

// Set the Monthly recurrence
var records = new MapiCalendarMonthlyRecurrencePattern
{
    Day = 15,
    Period = 1,
    PatternType = MapiCalendarRecurrencePatternType.Month,
    EndType = MapiCalendarRecurrenceEndType.EndAfterNOccurrences,
    OccurrenceCount = 5,
    WeekStartDay = DayOfWeek.Monday
};

การทำซ้ำรายเดือน: ชนิด EndAfterDate

"End By" ตัวเลือกใน Mapi Task จะทำได้โดยการตั้งค่า property OccurrenceCount ที่คำนวณโดยฟังก์ชัน GetOccurrenceCount() ฟังก์ชันนี้รับค่า start date , end date และสตริง RRULE. โค้ด snippet ต่อไปนี้แสดงวิธีสร้างการทำซ้ำในวันที่ 15 ของทุกเดือนระหว่างวันที่เริ่มต้นและสิ้นสุดตามวันที่.

// 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, 1);
StartDate = StartDate.Add(ts);

DateTime DueDate = new DateTime(2015, 7, 1);
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 recurrence = new MapiCalendarMonthlyRecurrencePattern
{
    Day = 15,
    Period = 1,
    PatternType = MapiCalendarRecurrencePatternType.Month,
    EndType = MapiCalendarRecurrenceEndType.EndAfterDate,
    OccurrenceCount = GetOccurrenceCount(StartDate, endByDate, "FREQ=MONTHLY;BYMONTHDAY=15;INTERVAL=1"),
    WeekStartDay = DayOfWeek.Monday,
    EndDate = endByDate
};

task.Recurrence = recurrence;
//task.Save(dataDir + "SetMonthlyEndAfterDateRecurrence_out.msg", TaskSaveFormat.Msg);

การทำซ้ำรายเดือน: ชนิด NeverEnd

โค้ด snippet ต่อไปนี้แสดงวิธีตั้งค่าประเภทการสิ้นสุดโดยใช้ MapiCalendarRecurrenceEndType.NeverEnd.

var recurrence = new MapiCalendarMonthlyRecurrencePattern
{
    Day = 15,
    Period = 1,
    PatternType = MapiCalendarRecurrencePatternType.Month,
    EndType = MapiCalendarRecurrenceEndType.NeverEnd,
    WeekStartDay = DayOfWeek.Monday,
};

ทำงานกับการทำซ้ำรายปี

Aspose.Email รองรับการสร้างการทำซ้ำรายปีโดยใช้ MapiCalendarMonthlyRecurrencePattern. โดยการตั้งค่า property period เป็น 12 เราสามารถสร้างรูปแบบการทำซ้ำรายปีได้. สามประเภทการสิ้นสุดการทำซ้ำของปฏิทิน Mapi ที่แตกต่างกันสามารถใช้ได้รวมถึง EndAfterNOccurrences, EndAfterDate และ NeverEnd. ส่วนนี้จะแสดงการสร้างรูปแบบการทำซ้ำรายปีที่หลากหลาย.

การทำซ้ำประจำปี: ชนิด EndAfterNOccurrences

ในชนิดการทำซ้ำนี้ จำนวนครั้งของการทำซ้ำต้องตั้งค่าพร้อมกับข้อมูลอื่น ๆ ดังต่อไปนี้:

  1. กำหนดวันที่เริ่ม, สิ้นสุด และกำหนดส่ง.
  2. สร้าง MapiTask.
  3. ตั้งค่าสถานะงานเป็น NotAssigned.
  4. สร้างอ็อบเจกต์การทำซ้ำรายเดือนโดยตั้งค่า property เช่น PatternType, Period, WeekStartDay, EndType และ OccurenceCount.
  5. ตั้งค่า property MapiTask.Recurrence ให้เป็นอ็อบเจกต์การทำซ้ำรายเดือนนี้เพื่อให้ได้การทำซ้ำรายปี.
  6. บันทึกข้อความนี้ลงดิสก์.

โค้ดตัวอย่างต่อไปนี้แสดงวิธีสร้างงานโดยตั้งค่าประเภทการสิ้นสุดการทำซ้ำเป็น EndAfterNOccurrence.


TimeZone localZone = TimeZone.CurrentTimeZone;
TimeSpan ts = localZone.GetUtcOffset(DateTime.Now);
DateTime StartDate = new DateTime(2015, 7, 1);
StartDate = StartDate.Add(ts);
DateTime DueDate = new DateTime(2015, 7, 1);
DateTime endByDate = new DateTime(2020, 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 Yearly recurrence
var recurrence = new MapiCalendarMonthlyRecurrencePattern
{
	Day = 15,
	Period = 12,
	PatternType = MapiCalendarRecurrencePatternType.Month,
	EndType = MapiCalendarRecurrenceEndType.EndAfterNOccurrences,
	OccurrenceCount = 3,
};
task.Recurrence = recurrence;
task.Save("Yearly.msg", TaskSaveFormat.Msg);

การทำซ้ำประจำปี: ชนิด EndAfterDate

"End By" ตัวเลือกใน Mapi Task จะทำได้โดยการตั้งค่า property OccurrenceCount ที่คำนวณโดยฟังก์ชัน GetOccurrenceCount() ฟังก์ชันนี้รับค่า start date, end date และสตริง RRULE. โค้ด snippet ต่อไปนี้แสดงวิธีสร้างการทำซ้ำในวันที่ 15 ของทุกเดือนที่ 7 ระหว่างวันที่เริ่มต้นและสิ้นสุดตามวันที่.

// Set the Yearly recurrence
var rec = new MapiCalendarMonthlyRecurrencePattern
{
    Day = 15,
    Period = 12,
    PatternType = MapiCalendarRecurrencePatternType.Month,
    EndType = MapiCalendarRecurrenceEndType.EndAfterDate,
    EndDate = endByDate,
    OccurrenceCount = GetOccurrenceCount(StartDate, endByDate, "FREQ=YEARLY;BYMONTHDAY=15;BYMONTH=7;INTERVAL=1"),
};
task.Recurrence = rec;

การทำซ้ำประจำปี: ชนิด NeverEnd

โค้ด snippet ต่อไปนี้แสดงวิธีตั้งค่าประเภทการสิ้นสุดโดยใช้ MapiCalendarRecurrenceEndType.NeverEnd.

// Set the Yearly recurrence
var recurrence = new MapiCalendarMonthlyRecurrencePattern
{
    Day = 15,
    Period = 12,
    PatternType = MapiCalendarRecurrencePatternType.Month,
    EndType = MapiCalendarRecurrenceEndType.NeverEnd,
};            

สร้างการทำซ้ำจากกฎการทำซ้ำ

Aspose.Email API มีความสามารถในการสร้าง Recurrence Pattern จาก Recurrence Rule (RRULE). มันจะวิเคราะห์ข้อมูลจาก RRULE ตามข้อกำหนด iCal RFC 5545 และสร้างรูปแบบการทำซ้ำโดยใช้เมธอด MapiCalendarRecurrencePatternFactory.FromString. โค้ด snippet ต่อไปนี้แสดงวิธีสร้างรูปแบบการทำซ้ำจากกฎการทำซ้ำ.

// The path to the File directory.
string dataDir = RunExamples.GetDataDir_Outlook();

DateTime startDate = new DateTime(2015, 7, 16);
DateTime endDate = new DateTime(2015, 8, 1);
MapiCalendar app1 = new MapiCalendar("test location", "test summary", "test description", startDate, endDate);

app1.StartDate = startDate;
app1.EndDate = endDate;

string pattern = "DTSTART;TZID=Europe/London:20150831T080000\r\nDTEND;TZID=Europe/London:20150831T083000\r\nRRULE:FREQ=DAILY;INTERVAL=1;COUNT=7\r\nEXDATE:20150831T070000Z,20150904T070000Z";
app1.Recurrence.RecurrencePattern = MapiCalendarRecurrencePatternFactory.FromString(pattern);

เพิ่มไฟล์แนบในเหตุการณ์ปฏิทินที่ทำซ้ำ

Aspose.Email API มีความสามารถในการเพิ่มไฟล์แนบให้กับเหตุการณ์ปฏิทินที่ทำซ้ำ.

DateTime startDate = new DateTime(2018, 7, 19).AddHours(12);
MapiCalendar calendar = new MapiCalendar("location1", "summary1", "description1", startDate, startDate.AddHours(1));

MapiCalendarEventRecurrence recurrence = new MapiCalendarEventRecurrence();
MapiCalendarRecurrencePattern pattern = recurrence.RecurrencePattern = new MapiCalendarDailyRecurrencePattern();
pattern.PatternType = MapiCalendarRecurrencePatternType.Day;
pattern.Period = 1;
pattern.EndType = MapiCalendarRecurrenceEndType.NeverEnd;

DateTime exceptionDate = startDate.AddDays(3);
MapiCalendarExceptionInfo exception = new MapiCalendarExceptionInfo
{
    Location = "exceptionLoc",
    Subject = "exceptionSubj",
    Body = "exceptionBody",
    OriginalStartDate = exceptionDate,
    StartDateTime = exceptionDate,
    EndDateTime = exceptionDate.AddHours(5),
    Attachments = new MapiAttachmentCollection(calendar)
};
exception.Attachments.Add("file.txt", Encoding.ASCII.GetBytes("hello, world!"));

pattern.Exceptions.Add(exception);
pattern.ModifiedInstanceDates.Add(exceptionDate);
pattern.DeletedInstanceDates.Add(exceptionDate);
calendar.Recurrence = recurrence;

using (var newPst = PersonalStorage.Create(dataDir + "AddAttachmentToMapiExceptionInfo.pst", FileFormatVersion.Unicode))
{
    var newFolder = newPst.CreatePredefinedFolder("Calendar", StandardIpmFolder.Appointments);
    newFolder.AddMapiMessageItem(calendar);
}