General Project Properties
Working with General Project Properties
Microsoft Project saves project properties, metadata, for every project. The properties include the project’s start and end dates, the current date and the status date, the type of calendar used and when a project is scheduled from. Aspose.Tasks for C++ lets you read and set project properties as described below.
Reading Project Information
The Project class has a number of properties that deal with project properties:
- StartDate: the project’s start date, of the DateTime data type.
- FinishDate: the project’s end date, of the DateTime data type.
- CurrentDate: the current date, of the DateTime data type.
- StatusDate: the date that the project’s progress will be reported, of the DateTime data type.
- ScheduleFromStart: defines whether the project is scheduled from the start or end data and takes a Boolean value.
- Calendar: the type of calendar used by the project, managed through the Aspose.Tasks.Calendar class.
To read project properties in Microsoft Project, click Project Information on the Project menu.
The code example given below demonstrates how to read and output the project start and end date, whether the project is scheduled from the start or end, author, last author, revision, keywords and comments.
1// The path to the documents directory.
2System::String dataDir = RunExamples::GetDataDir(System::Reflection::MethodBase::GetCurrentMethod(ASPOSE_CURRENT_FUNCTION)->get_DeclaringType().get_FullName());
3
4// Create a project reader instance
5System::SharedPtr<Project> project = System::MakeObject<Project>(dataDir + u"ReadProjectInfo.mpp");
6
7// Display project information
8if (NullableBool::to_Boolean(project->Get<NullableBool>(Prj::ScheduleFromStart())))
9{
10 System::Console::WriteLine(System::String(u"Project Finish Date : ") + project->Get<System::DateTime>(Prj::StartDate()).ToShortDateString());
11}
12else
13{
14 System::Console::WriteLine(System::String(u"Project Finish Date : ") + project->Get<System::DateTime>(Prj::FinishDate()).ToShortDateString());
15}
16System::Console::WriteLine(project->Get<System::String>(Prj::Author()));
17System::Console::WriteLine(project->Get<System::String>(Prj::LastAuthor()));
18System::Console::WriteLine(project->Get<int32_t>(Prj::Revision()));
19System::Console::WriteLine(project->Get<System::String>(Prj::Keywords()));
20System::Console::WriteLine(project->Get<System::String>(Prj::Comments()));
21System::Console::WriteLine(u"The program has run successfully");
Writing Project Information
Aspose.Tasks for C++ can write as well as read project information. The code example given below demonstrates how to set author, last author, revision, keywords and comments.
1try
2{
3 // The path to the documents directory.
4 System::String dataDir = RunExamples::GetDataDir(System::Reflection::MethodBase::GetCurrentMethod(ASPOSE_CURRENT_FUNCTION)->get_DeclaringType().get_FullName());
5
6 // Create project from template file
7 System::SharedPtr<Project> project = System::MakeObject<Project>(dataDir + u"WriteProjectInfo.mpp");
8
9 // Set project information
10 project->Set<System::String>(Prj::Author(), u"Author");
11 project->Set<System::String>(Prj::LastAuthor(), u"Last Author");
12 project->Set<int32_t>(Prj::Revision(), 15);
13 project->Set<System::String>(Prj::Keywords(), u"MSP Aspose");
14 project->Set<System::String>(Prj::Comments(), u"Comments");
15 project->Save(dataDir + u"WriteProjectInfo_out.mpp", Aspose::Tasks::Saving::SaveFileFormat::MPP);
16}
17catch (System::Exception& ex)
18{
19 System::Console::WriteLine(ex->get_Message() + u"\nThis example will only work if you apply a valid Aspose License. You can purchase full license or get 30 day temporary license from http://www.aspose.com/purchase/default.aspx.");
20}
21
Determining Project Version
Aspose.Tasks for C++ API provides the capability to retrieve project file information with simple API calls. The Project class’s Get method facilitates users to retrieve information using the static class Prj that exposes a number of properties related to the Project class. This topic shows how to retrieve version information.
The SaveVersion and LastSaved properties exposed by the Prj class are used to determine the project version and the date when the project was last saved. SaveVersion supports the Integer datatype, whereas LastSaved supports the DateTime datatype.
1// The path to the documents directory.
2System::String dataDir = RunExamples::GetDataDir(System::Reflection::MethodBase::GetCurrentMethod(ASPOSE_CURRENT_FUNCTION)->get_DeclaringType().get_FullName());
3
4// Read project from template file
5System::SharedPtr<Project> project = System::MakeObject<Project>(dataDir + u"DetermineProjectVersion.mpp");
6
7// Display project version
8System::Console::WriteLine(System::String(u"Project Version : ") + System::Convert::ToString(project->Get<int32_t>(Prj::SaveVersion())));
9System::Console::WriteLine(System::String(u"Last Saved : ") + project->Get<System::DateTime>(Prj::LastSaved()).ToShortDateString());
Writing Project Summary Information
Most programs save summary information with the files they save. Microsoft Project is no different. As well as the name of the author, the date the project was created and the last time it was edited and saved, it saves keywords, subject, comments and more. Aspose.Tasks for C++ lets you both read and write this type of information.
The Project’s class Set method can be used to write and Get method can be used to read Project summary information using the Prj class’s members. The file can be saved back after updating the summary information. To update the project summary information of an existing MPP file:
- Create an instance of Project class
- Set the various properties exposed by the Prj class to define summary information.
- Save the Project using the Save method of Project class
To see the file’s summary information:
- Find the file in a file browser.
- Right-click the file and select Properties.
- Go to the Details tab.
The code example given below demonstrates how to write a project summary information to the MPP file.
1// The path to the documents directory.
2System::String dataDir = RunExamples::GetDataDir(System::Reflection::MethodBase::GetCurrentMethod(ASPOSE_CURRENT_FUNCTION)->get_DeclaringType().get_FullName());
3
4// Instantiate Project class
5System::SharedPtr<Project> project = System::MakeObject<Project>(dataDir + u"WriteMPPProjectSummary.mpp");
6
7// Set project summary
8project->Set<System::String>(Prj::Author(), u"Author");
9project->Set<System::String>(Prj::LastAuthor(), u"Last Author");
10project->Set<int32_t>(Prj::Revision(), 15);
11project->Set<System::String>(Prj::Keywords(), u"MSP Aspose");
12project->Set<System::String>(Prj::Comments(), u"Comments");
13project->Save(dataDir + u"WriteMPPProjectSummary_out.mpp", Aspose::Tasks::Saving::SaveFileFormat::MPP);