Update Outline Code Definitions and Values

Aspose.Tasks for .NET provides the facility to add new outline code attributes to an existing Microsoft Project MPP file and save it back.

Updating Outline Code Definitions and Values

The following code sample defines new outline codes and sets their various fields. The outline codes and values are then added to the project outline codes and the updated data is saved back to MPP file. The steps involved in this activity are:

  1. Create an instance of Project Reader.
  2. Read the source MPP file.
  3. Define new OutlineValue objects and set the parameters.
  4. Add the outline codes to the project’s codes.
  5. Save the updated project data back to the MPP file.
 1Project project = new Project("New Project.mpp");
 2 
 3// Define outline code and its outline mask
 4OutlineCodeDefinition code1 = new OutlineCodeDefinition();
 5code1.Alias = "New task outline code1";
 6code1.FieldId = ((int)ExtendedAttributeTask.OutlineCode1).ToString();
 7code1.FieldName = "Outline Code1";
 8OutlineMask mask = new OutlineMask();
 9mask.Separator = "+";
10mask.Level = 1;
11mask.Type = MaskType.Numbers;
12code1.Masks.Add(mask);
13
14// Add outline value
15OutlineValue value = new OutlineValue();
16value.Description = "Value description";
17value.ValueId = 1;
18value.Value = "123456";
19value.Type = OutlineValueType.Number;
20code1.Values.Add(value);
21
22// Add outline code to project
23project.OutlineCodes.Add(code1);
24
25// Define outline code and its outline mask
26OutlineCodeDefinition code2 = new OutlineCodeDefinition();
27code2.Alias = "New resource outline code2";
28code2.FieldId = ((int)ExtendedAttributeResource.OutlineCode2).ToString();
29code2.FieldName = "Outline Code2";
30OutlineMask mask2 = new OutlineMask();
31mask2.Separator = "/";
32mask2.Level = 1;
33mask2.Type = MaskType.Numbers;
34code2.Masks.Add(mask2);
35
36// Add outline value
37OutlineValue value2 = new OutlineValue();
38value2.Description = "Value2 description";
39value2.ValueId = 2;
40value2.Value = "987654";
41value2.Type = OutlineValueType.Number;
42code2.Values.Add(value2);
43
44// Add outline code to project
45project.OutlineCodes.Add(code2);
46
47project.Save("Updated_project_out.mpp", SaveFileFormat.MPP);
Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.