Split Tasks in VSTO and Aspose.Tasks

Sometimes it is not possible to complete a task as scheduled and it needs to be split into two or more parts. Aspose.Tasks for .NET supports this Microsoft Project feature.

Code Examples

VSTO

Below is the code for VSTO Project to split tasks:

 1object missingValue = System.Reflection.Missing.Value;
 2
 3Application.FileOpenEx("MyProject.mpp",
 4
 5   missingValue, missingValue, missingValue, missingValue,
 6
 7   missingValue, missingValue, missingValue, missingValue,
 8
 9   missingValue, missingValue, PjPoolOpen.pjPoolReadOnly,
10
11   missingValue, missingValue, missingValue, missingValue,
12
13   missingValue);
14
15Project project = Application.ActiveProject;
16
17Task MyTask = project.Tasks[1];
18
19MyTask.Split(DateTime.Parse("01.11.13 08:00"), DateTime.Parse("09.11.13 08:00"));

This VSTO example shows how to split a task in a Microsoft Project file using the Interop library. After opening the project file with FileOpenEx, the code accesses the active project and retrieves a specific task by index. The Split method is then called on the task, creating an interruption in the schedule between the specified start and end dates. This can be useful for modeling delays or planned breaks in task execution.

Aspose.Tasks

The SplitParts property exposed by the Task class is used to determine the split parts of a task whereas SplitTask method exposed by the ResourceAssignment class is used to split a single task into multiple parts. SplitParts returns a collection of split parts whereas SplitTask method accepts start date, finish date and calendar arguments to split the task.

Splitting and Viewing Tasks in Microsoft Project

To split a task in Microsoft Project:

  1. Identify a long task and you want to divide.

  2. On the Task menu, select the Schedule group and click Split Task.

  3. Click at the position you want to split the task.

To see split tasks in Microsoft Project one can select Gantt Chart on the View menu. Split tasks are linked by a dotted line.

Creating and Splitting Task

To create and split a task, follow these steps:

  1. Create a new project.

  2. Create and assign a new calendar to the project.

  3. Create and add a new task in the project.

  4. Create and add a new resource assignment in the project.

  5. Use the SplitTask method exposed by the ResourceAssignment class to split the task.

  6. Write the new project to the disk.

The following code shows how to accomplish these tasks:

1Project project = new Project("MyProject.mpp");
2
3ResourceAssignment MyResource = project.ResourceAssignments[0];
4
5MyResource.SplitTask(DateTime.Parse("01.11.13 08:00"), DateTime.Parse("09.11.13 08:00"), project.Calendar);

This example demonstrates how to split a task in an MPP file using Aspose.Tasks for .NET. After loading a project, it accesses a ResourceAssignment from the project and uses the SplitTask method to define an interruption between two dates. The project’s calendar is passed to ensure scheduling aligns correctly. This method is useful for modeling task breaks such as delays, holidays, or part-time work schedules. Finally, the updated project can be saved back to disk.

Download Running Code

Download Sample Code

Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.