Tasks and Calendars

It is possible to associate calendars with particular tasks in Microsoft Project. Aspose.Task supports this functionality.

Tasks with Calendars

The Tsk class exposes the Calendar field used to set or get the calendar associated with a task. This property accepts or returns an Aspose.Tasks.Calendar object.

To create a calendar for a task in Microsoft Project:

  1. Open a project in Microsoft Project.
  2. On the Project menu, select Change Working Times, then Create New Calendar.
  3. To assign the calendar to a task, double-click the task in the Task Entry form.
  4. Select the Advanced tab.

Setting Task Calendar

Create a standard calendar and create a task. Assign the Calendar to the task.

1Project project = new Project();
3// Add task
4Task task = project.RootTask.Children.Add("Task1");
6// Create calendar and assign to task
7Calendar cal = project.Calendars.Add("TaskCal1");
8task.Set(Tsk.Calendar, cal);

Getting Task Calendar

Get task calendar by traversing the tasks in a project.

 1Project project = new Project("New Project.mpp");
 3// Declare ChildTasksCollector class object
 4ChildTasksCollector collector = new ChildTasksCollector();
 6// Use TaskUtils to get all children tasks in RootTask
 7TaskUtils.Apply(project.RootTask, collector, 0);
 9// Parse all the recursive children
10foreach (Task task in collector.Tasks)
12    Calendar cal = task.Get(Tsk.Calendar);
13    Console.WriteLine("Task calendar name: {0}", cal == null ? "None" : cal.Name);
Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.