Retrieving Calendar Exceptions

Retrieving Calendar Exceptions

When working with project calendars in Aspose.Tasks for .NET, you may need to retrieve exception dates such as holidays, special workdays, or planned non-working periods. These exceptions are essential for accurately analyzing project schedules and durations.

The Calendar class provides access to calendar exceptions via the Exceptions property. This property returns a collection of CalendarException objects, each of which represents a specific exception period.

Each CalendarException exposes properties such as:

By iterating through the Exceptions collection, you can examine or process all defined calendar exceptions in a project.

Example: Retrieving Calendar Exceptions

The following example demonstrates how to load a project and enumerate all calendar exceptions for its calendars.

 1Project project = new Project("New Project.mpp");
 2
 3// Access calendars
 4foreach (Calendar cal in project.Calendars)
 5{
 6    // Access calendar exceptions
 7    foreach (CalendarException calExc in cal.Exceptions)
 8    {
 9        Console.WriteLine("From: " + calExc.FromDate.ToShortDateString());
10        Console.WriteLine("To: " + calExc.ToDate.ToShortDateString());
11    }
12}

Conclusion

Accessing calendar exceptions allows you to gain a complete understanding of a project’s working time configuration. This is especially useful when performing custom scheduling logic, generating reports, or validating that non-working periods are correctly defined.

For more advanced scenarios, consider also reading:

Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.