Moving Tasks

Microsoft Project allows moving one task under another task. In this case, the child tasks of the selected tasks are also moved with it. Aspose.Tasks for .NET provides the same feature by moving a task under another task. This can be achieved by adding the selected task to the children of the new parent as shown in this article. The task can be moved under a different parent or the same parent.

Move Task Under Another Parent

Please note that using CalculationMode.None can improve performance when you add several tasks and call Recalculate method one time.

1Project project = new Project("New Project.mpp");
2project.CalculationMode = CalculationMode.Automatic;
3// Get Tasks by Ids
4Task task1 = project.RootTask.Children.GetByUid(6);
5Task task2 = project.RootTask.Children.GetByUid(3);
6// Adding Task 6 to another parent
8project.Save("MoveTaskUnderAnotherParent_out.mpp", SaveFileFormat.MPP);

Moving Task Under the Same Parent

The MoveToSibling method allows moving a task under the same parent to a specific position.

1Project project = new Project("New Project.mpp");
2// Move tasks with id 5 before task with id 3
3Task task = project.RootTask.Children.GetById(5);
5project.Save("MoveTaskUnderSameParent_out.mpp", SaveFileFormat.MPP);

Add Task To The End

To add a task to the end of the collection use -1.

1Project project = new Project("New Project.mpp");
2// Move tasks with id 2 to the end of the collection
3Task task = project.RootTask.Children.GetById(2);
5project.Save("MoveTaskAtTheEnd_out.mpp", SaveFileFormat.MPP);
Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.