Writing Updated Task Data to MPP
Contents
[
Hide
Show
]With Aspose.Tasks for .NET it is possible to update tasks and then write the updated data back to a Microsoft Project MPP file.
Updating Task Data
The following code snippet shows how to update a project’s task data and write it back to the MPP file. The step involved in this activity are:
- Create an instance of the Project class.
- Load the source MPP file.
- Create a Task and add it to the root task.
- Update the task parameters such as Deadline, NotesText, etc.
- Add additional tasks to the root task.
- Save the project.
The following code finds a task’s original and external ID through the cross project.
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);