Working with Outline Codes in a Project
Custom outline codes are tags you define for tasks or resources that provide a project structure that is different from WBS codes or outline numbers. Aspose.Tasks for .NET lets you retrieve these outline codes and their properties, such as Alias, AllLevelsRequired, Enterprise, EnterpriseOutlineCodeAlias, FieldId, FieldName, PhoneticAlias, Guid, Masks and Values.
Reading Outline Codes
The Project class exposes OutlineCodes which is a collection of OutlineCodeDefinition items. The OutlineCodeDefinition provides all the detail as shown in the following sample code.
The following lines of code retrieve a project’s outline code information.
1Project project = new Project("New Project.mpp");
2
3foreach (OutlineCodeDefinition ocd in project.OutlineCodes)
4{
5 Console.WriteLine("Alias = " + ocd.Alias);
6 if (ocd.AllLevelsRequired)
7 Console.WriteLine("It contains property: must have all levels");
8 else
9 Console.WriteLine("It does not contain property: must have all levels");
10 if (ocd.Enterprise)
11 Console.WriteLine("It is an enterprise custom outline code.");
12 else
13 Console.WriteLine("It is not an enterprise custom outline code.");
14
15 Console.WriteLine("Reference to another custom field for which this outline code definition is an alias is = " + ocd.EnterpriseOutlineCodeAlias);
16 Console.WriteLine("Field Id = " + ocd.FieldId);
17 Console.WriteLine("Field Name = " + ocd.FieldName);
18 Console.WriteLine("Phonetic Alias = " + ocd.PhoneticAlias);
19 Console.WriteLine("Guid = " + ocd.Guid);
20
21 // Display outline code masks
22 foreach (OutlineMask outlineMask in ocd.Masks)
23 {
24 Console.WriteLine("Level of a mask = " + outlineMask.Level);
25 Console.WriteLine("Mask = " + outlineMask.ToString());
26 }
27
28 // Display out line code values
29 foreach (OutlineValue outlineMask1 in ocd.Values)
30 {
31 Console.WriteLine("Description of outline value = " + outlineMask1.Description);
32 Console.WriteLine("Value Id = " + outlineMask1.ValueId);
33 Console.WriteLine("Value = " + outlineMask1.Value);
34 Console.WriteLine("Type = " + outlineMask1.Type);
35 }
36}
Check Outline Code Id Uniqueness
While working with OutlineCode, Aspose.Tasks shall check the uniqueness of the Outline Code Id and duplicate Ids will be replaced with unique values.
1Project project = new Project("New Project.mpp");
2
3OutlineCodeDefinition textOutline = new OutlineCodeDefinition();
4textOutline.FieldId = ExtendedAttributeTask.OutlineCode7.ToString("D");
5textOutline.Alias = "My Outline Code";
6
7project.OutlineCodes.Add(textOutline);
8
9OutlineMask mask = new OutlineMask();
10mask.Type = MaskType.Characters;
11textOutline.Masks.Add(mask);
12
13OutlineValue textValue = new OutlineValue();
14textValue.Value = "Text value 1";
15textValue.ValueId = 1;
16textValue.Type = OutlineValueType.Text;
17textValue.Description = "Text value descr 1";
18textOutline.Values.Add(textValue);
19
20project.Save("MultipleOutlineValues.mpp", SaveFileFormat.MPP);