Import/Export Projects to Primavera

Primavera’s Proprietary Exchange Format (XER), by Primavera Systems, Inc., is primarily associated with Primavera Project Management. Aspose.Tasks for Java provides the capability to export Microsoft Project Data to Primavera XER and XML formats. This article shows how to export project data to both these formats.

Importing Data from Primavera File

Importing Data from Primavera XML Format

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.

Importing Data from Primavera MPX File Format

Reading Project UIDs from Primavera XML file

A Primavera XML file may contain multiple projects, each having its own UID. Aspose.Tasks for Java 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.

Reading Primavera XML file with Multiple Projects

Importing Project Data from Primavera Database File

String url = "jdbc:sqlserver://";
String serverName = "192.168.56.3\\MSSQLSERVER";
String portNumber = "1433";
String databaseName = "PrimaveraEDB";
String userName = "privuser";
String password = "***";
PrimaveraDbSettings settings = new PrimaveraDbSettings(url+serverName + ":" + portNumber + ";databaseName=" + databaseName + ";user=" + userName + ";password=" + password, 4502);
// set driver name
settings.setDriverClassName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
// note that you have to set the classpath to include the sqljdbc.jar file or the sqljdbc4.jar file, otherwise  "Class not found" exception will be thrown
// here we add classpath dynamically just for testing needs:
addJDBCDriver(new File("c:\\Program Files (x86)\\Microsoft JDBC Driver 4.0 for SQL Server\\sqljdbc_4.0\\enu\\sqljdbc4.jar"));
Project project = new Project(settings);
private static void addJDBCDriver(File file) throws Exception
{
    Method method = URLClassLoader.class.getDeclaredMethod("addURL", new Class[]{URL.class});
    method.setAccessible(true);
    method.invoke(ClassLoader.getSystemClassLoader(), new Object[]{file.toURI().toURL()});
}

Support for SQLite Database

const string connectionString = "Data Source=d:\\DB\\PPMDBSQLite.db";
const int projectId = 4502;
PrimaveraDbSettings primaveraDbSettings = new PrimaveraDbSettings(connectionString, projectId);
primaveraDbSettings.setProviderInvariantName("System.Data.SQLite");
Project 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

Exporting Project Data to Primavera XER Format

Exporting Project Data to Primavera MPX Format

Primavera XML Save Options

If Primavera XML file doesn’t has 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 set to true.