These examples show how to open projects in MPX, MPP and MPD formats:
MPX File
The MPX file format is an ASCII file format that was designed to transfer project information between different versions of Microsoft Project. Detailed description of MPX format can be found on http://support.microsoft.com/default.aspx?scid=KB;EN-US;Q270139&
Microsoft Project 2000-2003 can read projects in MPX format but can't write it back.
[C#]
try {
// Open Microsoft Project file
MPXFile mpx = new MPXFile(filename);
}
catch (Exception ex) {
}
[Visual Basic]
Try
' Open Microsoft Project file
Dim mpx As MPXFile = New MPXFile(filename)
Catch ex As Exception
End Try
MPP File
The MPP file format is a Microsoft proprietary binary file format based upon Microsoft's OLE 2 Compound Document format. Aspose.Tasks can only read projects in MPP format. We are not currently planning to implement full read/write support for this format. Please use XML format instead.
[C#]
try {
// Open Microsoft Project file
MPXFile mpp = new MPPFile(filename);
}
catch (Exception ex) {
}
[Visual Basic]
Try
' Open Microsoft Project file
Dim mpp As MPXFile = New MPPFile(filename)
Catch ex As Exception
End Try
MPD File / Project Database
To read database of MS Project Server or local database in MPD format (Access database) we should create connection string and open database. After that we can iterate all projects stored in the database and open it separately.
[C#]
try {
string connectionStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Projects\\sample.mpd";
MPDDatabase mpd;
// Open Microsoft Project database
mpd = new MPDDatabase(connectionStr);
if (mpd != null) {
System.Collections.IEnumerator iter = mpd.GetEnumerator();
while (iter.MoveNext() == true) {
// Iterate all projects and open it.
// MPDProjectInfo object returned by iterator contains Name of a project,
// Start and Finish dates, and unique ID of a project in a database.
MPDProject mp = mpd.ReadMPDProject((MPDProjectInfo)(iter.Current));
}
}
}
catch (System.Exception ex) {
}
[Visual Basic]
Try
Dim connectionStr As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Projects\\sample.mpd"
Dim mpd As MPDDatabase
' Open Microsoft Project database
mpd = New MPDDatabase(connectionStr)
If Not mpd Is Nothing Then
Dim iter As System.Collections.IEnumerator = mpd.GetEnumerator()
While iter.MoveNext() = True
' Iterate all projects and open it.
' MPDProjectInfo object returned by iterator contains Name of a project,
' Start and Finish dates, and unique ID of a project in a database.
Dim mp As MPDProject = mpd.ReadMPDProject(CType((iter.Current), MPDProjectInfo))
End While
End If
Catch ex As System.Exception
End Try
XML File (MSPDI - Microsoft Project Data Interchange)
Last versions of MS Project can store and read project information in XML format.
Aspose.Tasks has full read/write support for this format.
[C#]
try {
// Open XML file
MPXFile xml = new XMLFile(filename);
}
catch (Exception ex) {
}
[Visual Basic]
Try
' Open XML file
Dim xml As MPXFile = New XMLFile(filename)
Catch ex As Exception
End Try