Adding and Removing Calendar Exceptions

Working with Calendar Exceptions

Aspose.Tasks helps you manage calendar exceptions. The Exceptions property exposed by the Calendar class that represents a List of CalendarException objects and is used to add or remove the calendar exceptions.

The following example shows how to add, remove and display exceptions.

 1Project project = new Project("New Project.mpp");
 2
 3// Remove an exception
 4Calendar cal = project.Calendars.ToList()[0];
 5if (cal.Exceptions.Count > 1)
 6{
 7    CalendarException exc = cal.Exceptions.ToList()[0];
 8    cal.Exceptions.Remove(exc);
 9}
10
11// Add an exception
12CalendarException calExc = new CalendarException();
13calExc.FromDate = new System.DateTime(2009, 1, 1);
14calExc.ToDate = new System.DateTime(2009, 1, 3);
15cal.Exceptions.Add(calExc);
16
17// Display exceptions
18foreach (CalendarException calExc1 in cal.Exceptions)
19{
20    Console.WriteLine("From" + calExc1.FromDate.ToShortDateString());
21    Console.WriteLine("To" + calExc1.ToDate.ToShortDateString());
22}
Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.