MPP to XML

MPP File to XML Conversion | Export Microsoft Project file to XML in C#

Microsoft Project is one of the most popular and widespread project management software. The software allows you to plan projects, assign tasks, manage resources and workflows, create reports, etc. However, MS Project doesn’t provide an opportunity to open or edit the MPP format file for non-registered users. This means if you don’t have a purchased Microsoft Project license, you cannot work with MPP files. So when sharing project files, the recipient must have an MS Project subscription even if s/he only wants to view it. Therefore, the conversion of the MPP file to XML can be a good solution.

Microsoft Project File Conversion API

Aspose.Tasks Cloud is our REST API offering the features to create, process as well as transform project management files to various Supported File Formats. In order to process the project file, you can load the file from cloud storage, import the project from primavera DB format (primavera SQLite.db or primavera XML), and import the project from the database with a specified connection string or import the project from Project Online. As per the scope of this article, we are going to use Aspose.Tasks Cloud SDK for .NET which is available for download at NuGet and GitHub. Please execute the following command in the terminal to install the SDK via NuGet:

nuget install Aspose.Tasks-Cloud

In order to directly install the SDK in the NuGet package manager, please execute the following command:

 PM> Install-Package Aspose.Tasks-Cloud

Now we need to create a free subscription account by visiting Aspose.Cloud dashboard. Use your GitHub or Google account to simply Sign Up or, click on the Create a new Account and obtain your Client Credentials.

Convert MPP to XML in C#

Please follow the steps specified below to perform the conversion operation using C# .NET

  • First, we need to create a TasksApi object while passing ClientSecret and ClientId details as arguments
  • Secondly, load the content of MPP to the FileStream instance
  • Now create an object of PostCreateRequest class which requires a filename and Stream instance containing MPP content
  • Call the UploadFile(…) method of TasksApi to upload a file to Cloud storage
  • Then, create an object of GetTaskDocumentWithFormatRequest class
  • Specify XML value from ProjectFileFormat enumeration and assign the value to Format property of GetTaskDocumentWithFormatRequest object
  • Now call the GetTaskDocumentWithFormat(…) method to perform the conversion operation
  • Since the output of the last step is saved in the Stream instance, we need to use File.Create object to save the output on the local drive. The details can be seen in saveToDisk(..) custom method.

The sample files used in above example can be found over Home move plan.mpp and Converted.xml.

MPP to XML using cURL Commands

The cURL commands provide an excellent mechanism to access REST APIs through the command line terminal. Since Aspose.Tasks Cloud is also developed as per REST principles, so we can also access the API using cURL commands. But as the APIs are only accessible to authorized persons, so based on Client ID and Client Secret details, we need to create a JWT access token. Please execute the following command for JWT access token generation.

 curl -v "https://api.aspose.cloud/connect/token" \
 -X POST \
 -d "grant_type=client_credentials&client_id=4db2f826-bf9c-42e7-8b2a-8cbca2d15553&client_secret=d757548a9f2558c39c2feebdf85b4c44" \
 -H "Content-Type: application/x-www-form-urlencoded" \
 -H "Accept: application/json"

In order to upload the MPP file to Cloud storage, please execute the following cURL command.

curl -X PUT "https://api.aspose.cloud/v3.0/tasks/storage/file/Home%20move%20plan.mpp" \
-H  "accept: application/json" \
-H  "authorization: Bearer <JWT Token>" \
-H  "Content-Type: multipart/form-data" \
-d {"File":{}}

Finally, call the following command to perform the MPP conversion to XML format and save the output on the local drive (on the specified path).

curl -X GET "https://api.aspose.cloud/v3.0/tasks/Home%20move%20plan.mpp/format?format=xml&returnAsZipArchive=false" \
-H  "accept: multipart/form-data" \
-H  "authorization: Bearer <JWT Token>" \
-o Converted.xml

Conclusion

The article has shared the details on how to convert the Microsoft Project file to XML using the C# .NET code snippet. Furthermore, please note that all our Cloud SDKs are developed under an MIT license, so their complete code snippet can be downloaded from GitHub. In case you encounter any issues while using the API or you have any related queries, please feel free to contact us via the Free Product support forum.

We also recommend visiting the following links to learn more about