Import/Export Projects to Primavera

Primavera Proprietary Exchange Format (XER), by Oracle Inc., is primarily associated with Primavera P6 Project Management solution. Aspose.Tasks for .NET provides the capability to export Microsoft Project Data to Primavera XER as well as XML (or P6XML) formats. This article shows how to import or export MS Project MPP data to Primavera supported formats.

Importing Data from Primavera File

Importing Data from Primavera XML File Formats

Aspose.Tasks can import Primavera XML similar to Microsoft Project XML and MPP formats. The Project class provides the capability of loading such type of file using the same constructor as used for other Project files.

1Project project = new Project("Project.xml");
2ProjectFileInfo info = Project.GetProjectFileInfo("Project.xml");
3Console.WriteLine(info.ProjectFileFormat);

Importing Data from Primavera MPX File Formats

1Project project = new Project("Primavera1.mpx");
2ProjectFileInfo info = Project.GetProjectFileInfo("primavera1.mpx");
3Console.WriteLine(info.ProjectFileFormat);

Reading Project UIDs from Primavera XML file

A Primavera XML file may contain multiple projects, each having its own UID. Aspose.Tasks for .NET API provides the capability to read all such UIDs from the project and then load a project using a specific id from the list of UIDs.

1PrimaveraXmlReader reader = new PrimaveraXmlReader("Project.xml");
2List<int> listOpProjectUids = reader.GetProjectUids();

Reading Primavera XML file with Multiple Projects

1PrimaveraXmlReadingOptions options = new PrimaveraXmlReadingOptions();
2options.ProjectUid = 4557;
3// Returns project with special Uid
4Project project = new Project("Project.xml", options); 

Importing Project Data From Primavera Database

Aspose.Tasks for .NET API provides the capability to read Project data from Primavera Database. The following example code shows how to use the Project class for reading from the database.

 1SqlConnectionStringBuilder sb = new SqlConnectionStringBuilder();
 2sb.DataSource = "192.168.56.3,1433";
 3sb.Encrypt = true;
 4sb.TrustServerCertificate = true;
 5sb.InitialCatalog = "PrimaveraEDB";
 6sb.NetworkLibrary = "DBMSSOCN";
 7sb.UserID = "privuser";
 8sb.Password = "***";
 9
10// Initialize a new instance of the PrimaveraDbSettings class with connection string and project id
11PrimaveraDbSettings settings = new PrimaveraDbSettings(sb.ConnectionString, 4502);
12
13// Initialize a new instance of the Project class
14Project project = new Project(settings);

Support for Primavera SQLite Database

Aspose.Tasks for .NET provides support for reading project data from Primavera P6 standalone SQLite database.

1const int projectId = 4502;
2// Create Primavera DB Settings using connection string and project id
3PrimaveraDbSettings primaveraDbSettings = new PrimaveraDbSettings("Data Source=\\PPMDBSQLite.db", projectId);
4primaveraDbSettings.ProviderInvariantName = "System.Data.SQLite";
5// Create new project using primavera db settings
6Project project = new Project(primaveraDbSettings);

Exporting Project Data in Primavera Formats

The SaveFileFormat enumerator is used to specify the project export type as Primavera XML or XER.

Exporting Project Data to Primavera XML Format

1Project project = new Project("New Project.mpp");
2project.Save("ExportProjectDataToXMLFormat_out.xml", SaveFileFormat.PrimaveraP6XML);

Exporting Project Data to Primavera XER Format

1Project project = new Project("New Project.mpp");
2project.Save("ExportProjectDataToXERFormat_out.mpp", SaveFileFormat.PrimaveraXER);

Exporting Project Data to Primavera MPX Format

1Project project = new Project("New Project.mpp");
2project.Save("ExportProjectDataToPrimaveraMPXFormat_out.xml", SaveFileFormat.MPX);

Primavera XML Save Options

If Primavera XML file doesn’t have any WBS inside (only Activities), Aspose.Tasks can’t read properly this type of file, because the API needs a root task to create a tree of tasks. In this case, the API creates a RootTask, even if it doesn’t exist in the file, to be able to read these particular files. If the user wants to save after reading, It’ll be saving with created RootTask, which did not exist before reading. This option helps to decide how to save into the file with created RootTask or not. By default it is set to true.

1Project project = new Project("project.xml");
2
3// Specify xml save options
4PrimaveraXmlSaveOptions options = new PrimaveraXmlSaveOptions();
5options.SaveRootTask = false;
6project.Save("UsingPrimaveraXMLSaveOptions_out.xml", options);
Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.