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:
- Create an instance of the Project class.
- Load the source MPP file.
- Access the Task object and modify its properties.
- Update parameters such as Deadline, NotesText, Start/Finish dates, or IDs.
- Optionally add new tasks to the root task or subtasks.
- 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
- You can update most task properties, including Deadlines, Notes, Start/Finish dates, and custom fields.
- Tasks can be added, modified, or deleted programmatically before saving.
- Updated projects can be saved in MPP and XML formats without requiring Microsoft Project installed.
- Task IDs (Original ID, External ID) can be accessed for cross-project references.
- Aspose.Tasks ensures data integrity when writing back to project files.
FAQ
Q: Can I add new tasks while updating an existing project?
- Yes. You can insert new tasks into the root task or as subtasks before saving.
Q: Are custom fields preserved when writing updated data?
- Yes. Aspose.Tasks maintains custom field values when saving updated MPP/XML files.
Q: Do I need Microsoft Project installed to save changes?
- No. Aspose.Tasks works independently and does not require Microsoft Project.
Q: Can I update task resources together with task data?
- Yes. You can modify both task details and assigned resources programmatically.
Q: How do I track cross-project task references?
- Use the Original ID and External ID properties to identify linked tasks across multiple projects.