Writing Metadata to MPP

Aspose.Tasks for .NET provides a facility for writing metadata to MPP files for calendars, tasks, task links, resources and resource assignments.

Writing Metadata to Microsoft Project Files

The following metadata is used in this example:

Here IsMarked and IgnoreWarnings are newly added fields for a task. Similarly for resources, the TeamAssignmentPool and CostCenter properties are provided.

The following steps are followed in the sample code to demonstrate how to write metadata to MPP files:

  1. Open a new, blank MPP file.
  2. Add working times on Monday of the project calendar and change the project calendar name.
  3. Add three tasks with task links and lags.
  4. Add two resources, one budget work and one budget cost resource (four in total).
  5. Assign budget resources to the project root task (the project summary task).
  6. Assign another two resources to the first and second tasks.
  7. Set the project baseline.
  8. Add a new task extended attribute.
  9. Save changes as an MPP file.
 1Project project = new Project("New Project.mpp");
 3// Add working times to project calendar
 4WorkingTime wt = new WorkingTime();
 5wt.FromTime = new DateTime(2010, 1, 1, 19, 0, 0);
 6wt.ToTime = new DateTime(2010, 1, 1, 20, 0, 0);
 7WeekDay day = project.Get(Prj.Calendar).WeekDays.ToList()[1];
10// Change calendar name
11project.Get(Prj.Calendar).Name = "CHANGED NAME!";
13// Add tasks and set task meta data
14Task task = project.RootTask.Children.Add("Task 1");
15task.Set(Tsk.DurationFormat, TimeUnitType.Day);
16task.Set(Tsk.Duration, project.GetDuration(3));
17task.Set(Tsk.Contact, "Rsc 1");
18task.Set(Tsk.IsMarked, true);
19task.Set(Tsk.IgnoreWarnings, true);
20Task task2 = project.RootTask.Children.Add("Task 2");
21task2.Set(Tsk.DurationFormat, TimeUnitType.Day);
22task2.Set(Tsk.Contact, "Rsc 2");
24// Link tasks
25project.TaskLinks.Add(task, task2, TaskLinkType.FinishToStart, project.GetDuration(-1, TimeUnitType.Day));
27// Set project start date
28project.Set(Prj.StartDate, new DateTime(2013, 8, 13, 9, 0, 0));
30// Add resource and set resource meta data
31Resource resource = project.Resources.Add("Rsc 1");
32resource.Set(Rsc.Type, ResourceType.Work);
33resource.Set(Rsc.Initials, "WR");
34resource.Set(Rsc.AccrueAt, CostAccrualType.Prorated);
35resource.Set(Rsc.MaxUnits, 1);
36resource.Set(Rsc.Code, "Code 1");
37resource.Set(Rsc.Group, "Workers");
38resource.Set(Rsc.EMailAddress, "1@gmail.com");
39resource.Set(Rsc.WindowsUserAccount, "user_acc1");
40resource.Set(Rsc.IsGeneric, new NullableBool(true));
41resource.Set(Rsc.AccrueAt, CostAccrualType.End);
42resource.Set(Rsc.StandardRate, 10);
43resource.Set(Rsc.StandardRateFormat, RateFormatType.Day);
44resource.Set(Rsc.OvertimeRate, 15);
45resource.Set(Rsc.OvertimeRateFormat, RateFormatType.Hour);
46resource.Set(Rsc.IsTeamAssignmentPool, true);
47resource.Set(Rsc.CostCenter, "Cost Center 1");
49// Create resource assignment and set resource assignment meta data
50ResourceAssignment assignment = project.ResourceAssignments.Add(task, resource);
51assignment.Set(Asn.Uid, 1);
52assignment.Set(Asn.Work, task.Get(Tsk.Duration));
53assignment.Set(Asn.RemainingWork, assignment.Get(Asn.Work));
54assignment.Set(Asn.RegularWork, assignment.Get(Asn.Work));
55task.Set(Tsk.Work, assignment.Get(Asn.Work));
57resource.Set(Rsc.Work, task.Get(Tsk.Work));
58assignment.Set(Asn.Start, task.Get(Tsk.Start));
59assignment.Set(Asn.Finish, task.Get(Tsk.Finish));
61// Add extended attribute for project and task
62ExtendedAttributeDefinition attr = ExtendedAttributeDefinition.CreateTaskDefinition(CustomFieldType.Flag, ExtendedAttributeTask.Flag1,  "My Flag Field");
65ExtendedAttribute taskAttr = attr.CreateExtendedAttribute();
66taskAttr.FlagValue = true;
69project.Save("WriteMetaData_out.mpp", SaveFileFormat.MPP);
Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.