Propiedades generales del proyecto

Trabajar con propiedades generales del proyecto

Microsoft Project guarda propiedades del proyecto, metadatos, para cada proyecto. Las propiedades incluyen las fechas de inicio y finalización del proyecto, la fecha actual y la fecha de estado, el tipo de calendario utilizado y cuando se programa un proyecto. Aspose.Tasks para C ++ le permite leer y establecer propiedades del proyecto como se describe a continuación.

Lectura de información del proyecto

La clase Proyecto tiene una serie de propiedades que se ocupan de las propiedades del proyecto:

To read project properties in Microsoft Project, click Project Information on the Project menu.

project information in Microsoft Project 2010

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:

  1. Create an instance of Project class

  2. Set the various properties exposed by the Prj class to define summary information.

  3. Save the Project using the Save method of Project class

To see the file’s summary information:

  1. Find the file in a file browser.

  2. Right-click the file and select Properties.

  3. 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);
Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.