Creating, Reading and Saving Projects

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 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 XML project files only. The following lines of code create a simple project file in 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.

The project information for the output XML file


Create an Empty Project Using File Stream

The given below code example shows how to create an empty project using file stream with Aspose.Tasks. 

Reading a Project File

Aspose.Tasks lets you open existing files and manipulate them as well as creating new files. This topic shows how a Project file can be read using Project class’s constructor.

The Project class constructor accepts a valid FileInputStream object or path to MPP or XML document and returns a Project object which can be used to manipulate project data.

Reading Project Files as a Template


 //Read a project from template

Project project = new Project("d:\\Project1.mpp");

Reading Project Data from Microsoft Project Database

Aspose.Tasks API now allows to read Project data from Microsoft Project database. The SqlConnectionStringBuilder and MspDbSettings classes can be used to accomplish this purpose providing connection string settings for connection to the database.

Reading Project Data from Microsoft Access Database (MPD)

Ignoring invalid characters during loading Project

Some files may have invalid characters in the custom fields. MS Project does not allow invalid character so the files have been created or manipulated with automation or some other tools. If these be loaded using the API, they may lead to an exception. In order to ignore such invalid characters, the overloaded constructor of Project class can be used with the delegate method ParseErrorCallBack.

Read Password Protected Projects (2003 Format)

 This topic shows how to read password protected projects in 2003 format using Aspose.Tasks for Java.

The Project class exposes the Project() constructor which is capable of reading password protecte*d files in 2003 format. Saving a password-protected file is not supported yet.

To read a password-protected project file:

  1. Load a Microsoft Project file.
  2. In the constructor, provide a password as the second argument to the constructor.

The following lines of code show how to achieve this using Java.

Reading Project Online

The ProjectOnlineReader class provides the methods to retrieve projects from the specified Project Online account. The ProjectServerCredentials class shall be used to provide credentials which are used to connect to Project Online. Previously, the Microsoft.SharePoint.Client.Runtime assembly was used to retrieve AuthToken but now Aspose.Tasks provides an option to specify SiteUrl, username, and password in order to create a connection to Project Online.  

The following lines of code show how to read project online.