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;
2Application.FileOpenEx("MyProject.mpp",
3 missingValue, missingValue, missingValue, missingValue,
4 missingValue, missingValue, missingValue, missingValue,
5 missingValue, missingValue, PjPoolOpen.pjPoolReadOnly,
6 missingValue, missingValue, missingValue, missingValue,
7 missingValue);
8Project project = Application.ActiveProject;
9Task MyTask = project.Tasks[1];
10MyTask.Split(DateTime.Parse("01.11.13 08:00"), DateTime.Parse("09.11.13 08:00"));
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:
- Identify a long task and you want to divide.
- On the Task menu, select the Schedule group and click Split Task.
- 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:
- Create a new project.
- Create and assign a new calendar to the project.
- Create and add a new task in the project.
- Create and add a new resource assignment in the project.
- Use the SplitTask method exposed by the ResourceAssignment class to split the task.
- Write the new project to the disk.
The following code shows how to accomplish these tasks:
1Project project = new Project("MyProject.mpp");
2ResourceAssignment MyResource = project.ResourceAssignments[0];
3MyResource.SplitTask(DateTime.Parse("01.11.13 08:00"), DateTime.Parse("09.11.13 08:00"), project.Calendar);