Update Outline Code Definitions and Values

Aspose.Tasks for C++ API 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 its various fields. The outlines 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.
 1System::String dataDir = RunExamples::GetDataDir(System::Reflection::MethodBase::GetCurrentMethod(ASPOSE_CURRENT_FUNCTION)->get_DeclaringType().get_FullName());
 2System::SharedPtr<Project> project = System::MakeObject<Project>(dataDir + u"project.mpp");
 3        
 4// Define outline code and its outline mask
 5System::SharedPtr<OutlineCodeDefinition> code1 = System::MakeObject<OutlineCodeDefinition>();
 6code1->set_Alias(u"New task outline code1");
 7code1->set_FieldId(System::Convert::ToString(((int32_t)Aspose::Tasks::ExtendedAttributeTask::OutlineCode1)));
 8code1->set_FieldName(u"Outline Code1");
 9System::SharedPtr<OutlineMask> mask = System::MakeObject<OutlineMask>();
10mask->set_Separator(u"+");
11mask->set_Level(1);
12mask->set_Type(Aspose::Tasks::MaskType::Numbers);
13code1->get_Masks()->Add(mask);
14        
15// Add outline value
16System::SharedPtr<OutlineValue> value = System::MakeObject<OutlineValue>();
17value->set_Description(u"Value description");
18value->set_ValueId(1);
19value->set_Value(u"123456");
20value->set_Type(Aspose::Tasks::OutlineValueType::Number);
21code1->get_Values()->Add(value);
22        
23// Add outline code to project
24project->get_OutlineCodes()->Add(code1);
25        
26// Define outline code and its outline mask
27System::SharedPtr<OutlineCodeDefinition> code2 = System::MakeObject<OutlineCodeDefinition>();
28code2->set_Alias(u"New rsc outline code2");
29code2->set_FieldId(System::Convert::ToString(((int32_t)Aspose::Tasks::ExtendedAttributeResource::OutlineCode2)));
30code2->set_FieldName(u"Outline Code2");
31System::SharedPtr<OutlineMask> mask2 = System::MakeObject<OutlineMask>();
32mask2->set_Separator(u"/");
33mask2->set_Level(1);
34mask2->set_Type(Aspose::Tasks::MaskType::Numbers);
35code2->get_Masks()->Add(mask2);
36        
37// Add outline value
38System::SharedPtr<OutlineValue> value2 = System::MakeObject<OutlineValue>();
39value2->set_Description(u"Value2 description");
40value2->set_ValueId(2);
41value2->set_Value(u"987654");
42value2->set_Type(Aspose::Tasks::OutlineValueType::Number);
43code2->get_Values()->Add(value2);
44        
45// Add outline code to project
46project->get_OutlineCodes()->Add(code2);
47        
48// Save project as MPP
49project->Save(dataDir + u"Updated_project_out.mpp", Aspose::Tasks::Saving::SaveFileFormat::MPP);
Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.