Moving Tasks

In Microsoft Project, tasks can be moved within the task hierarchy to reflect changes in project structure.

  • Moving a task under a new parent also moves all its child tasks.
  • Aspose.Tasks for .NET provides APIs to replicate this behavior programmatically.

Moving a Task Under Another Parent

Aspose.Tasks allows reassigning a task to a new parent. This is useful when reorganizing project hierarchies.

For better performance when moving multiple tasks, set the project’s calculation mode to CalculationMode.None and call Recalculate only once after all moves are completed.

Example:

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
7task2.Children.Add(task1);
8project.Save("MoveTaskUnderAnotherParent_out.mpp", SaveFileFormat.MPP);

This example demonstrates how to move a task under a different parent task.

Moving a Task Under the Same Parent

If you need to reorder tasks under the same parent, use the MoveToSibling method.

Example:

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);
4task.MoveToSibling(3);
5project.Save("MoveTaskUnderSameParent_out.mpp", SaveFileFormat.MPP);

This example shows how to move a task to a new position within the same parent.

Adding a Task to the End

When adding or moving tasks, you can append them to the end of a collection by using -1 as the target index.

Example:

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);
4task.MoveToSibling(-1);
5project.Save("MoveTaskAtTheEnd_out.mpp", SaveFileFormat.MPP);

This example moves a task to the end of its parent’s task list.

Key Notes

FAQ

Q: When I move a task under another parent, will its child tasks move too?

Q: How can I move multiple tasks efficiently?

Q: Can I reorder tasks without changing their parent?

Q: Does this functionality work with both MPP and XML project formats?

Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.