How to Write Updated Task Data to MPP

Aspose.Tasks for .NET enables developers to update task information (such as deadlines, notes, IDs, and structure) and then write these changes back to Microsoft Project files in MPP or XML format. This makes it possible to programmatically modify existing projects without manually editing them in Microsoft Project.

Updating Task Data in Aspose.Tasks

When working with project schedules, it is common to update tasks after planning — for example, adjusting deadlines, changing task notes, or adding new items. Aspose.Tasks provides a simple workflow for this process:

  1. Create an instance of the Project class.
  2. Load the source MPP file.
  3. Access the Task object and modify its properties.
  4. Update parameters such as Deadline, NotesText, Start/Finish dates, or IDs.
  5. Optionally add new tasks to the root task or subtasks.
  6. Save the updated project back to MPP/XML.

Example: Updating Task Data and Saving to MPP

The following example demonstrates how to update a task’s deadline, add notes, and find task IDs before writing the updated project back to disk:

 1Project project = new Project("New Project.mpp");
 2
 3// Set project start date
 4project.Set(Prj.StartDate, new DateTime(2012, 07, 29, 8, 0, 0));
 5
 6// Add summary task and set its properties
 7Task summary = project.RootTask.Children.Add("Summary task");
 8Task task = summary.Children.Add("First task");
 9task.Set(Tsk.Duration, project.GetDuration(3));
10task.Set(Tsk.Deadline, task.Get(Tsk.Start).AddDays(10));
11task.Set(Tsk.NotesText, "The first task.");
12task.Set(Tsk.DurationFormat, TimeUnitType.MinuteEstimated);
13task.Set(Tsk.ConstraintType, ConstraintType.FinishNoLaterThan);
14task.Set(Tsk.ConstraintDate, task.Get(Tsk.Deadline).AddDays(-1));
15
16
17// Create 10 new sub tasks for summary task
18for (int i = 0; i < 10; i++)
19{
20    Task subTask = summary.Children.Add(string.Format("Task{0}", i + 2));
21    subTask.Set(Tsk.Duration, task.Get(Tsk.Duration).Add(project.GetDuration(i + 1)));
22    subTask.Set(Tsk.DurationFormat, TimeUnitType.Day);
23    subTask.Set(Tsk.Deadline, task.Get(Tsk.Deadline).AddDays(i + 1));
24}
25
26project.Save("UpdateTaskData_out.mpp", SaveFileFormat.MPP);

This snippet shows how developers can programmatically modify existing tasks and preserve updates in MPP files. This is particularly useful when synchronizing external systems with Microsoft Project data.

Key Notes

FAQ

Q: Can I add new tasks while updating an existing project?

Q: Are custom fields preserved when writing updated data?

Q: Do I need Microsoft Project installed to save changes?

Q: Can I update task resources together with task data?

Q: How do I track cross-project task references?

Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.