Creating and Saving Microsoft Project (MPP/XML) Files

Aspose.Tasks for C++ lets you work with Microsoft Project (MPP/XML) files without having Microsoft Project installed, or using Microsoft Office Automation. A powerful and flexible API, Aspose.Tasks saves you time and effort by giving you the tools you need to write efficient code for manipulating project files in your C++ applications.

Aspose.Tasks can be used to open existing files or creating a new files. This article explains how to create a new and empty project file from the stream using the Project class as well as open existing files.

Creating an Empty Project File

The Project class is the main class in Aspose.Tasks used to set and get properties associated with a project, as well as project behavior. The Save method offered by this class makes it possible to render the Project to various output formats such as XML, MPP, PDF, HTML, etc. with a single API call. This method accepts a file stream or file name, and one of the values provided by the SaveFileFormat enumeration type.

At present, Aspose.Tasks provides the facility to create the XML project files only. The following lines of code create a simple project file in the XML format.

The XML project file can be opened in Microsoft Project:

  1. On the File menu, select Open.
  2. Select the XML format (*.xml) option from the file types and browse to the output XML file.
  3. On the Project menu, select Project Information

Create an Empty Project And Saving as XML File

1// Create empty project
2System::SharedPtr<Project> project = System::MakeObject<Project>();
3    
4// Save project as xml 
5project->Save(dataDir + u"EmptyProjectSaveXML_out.xml", Aspose::Tasks::Saving::SaveFileFormat::XML);

Create an Empty Project and Save to Stream

 1// Create a project instance
 2System::SharedPtr<Project> newProject = System::MakeObject<Project>();
 3    
 4// Create a file stream
 5{
 6    System::SharedPtr<System::IO::FileStream> projectStream = System::MakeObject<System::IO::FileStream>(dataDir + u"EmptyProjectSaveStream_out.xml", System::IO::FileMode::Create, System::IO::FileAccess::Write);
 7    // Clearing resources under 'using' statement
 8    System::Details::DisposeGuard<1> __dispose_guard_0({ projectStream});
 9    // ------------------------------------------
10    
11    try
12    {
13        // Write the stream into XML format
14        newProject->Save(projectStream, Aspose::Tasks::Saving::SaveFileFormat::XML);
15    }
16    catch(...)
17    {
18        __dispose_guard_0.SetCurrentException(std::current_exception());
19    }
20}

Create an Empty Project and Save to MPP

1// Create empty project
2System::SharedPtr<Project> project = System::MakeObject<Project>();
3
4// Save project as MPP 
5project->Save(dataDir + u"project.mpp", Aspose::Tasks::Saving::SaveFileFormat::MPP);
Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.