MPP to XML – Convert MPP to XML in C#

MPP to XML

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. Similarly, MPP is a format for a project file created in MS Project and contains all the information about the project: workload, deadlines, reports.

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. To solve this limitation, the conversion of MPP files to XML format can be a good solution.

Project file processing API

Aspose.Tasks Cloud is our REST API offering the features to create, process as well as transform project management files to other Supported File Formats. Using Cloud API, you can build cloud-based, web & desktop, and mobile applications. In your applications, you can perform project creation, scheduling, resource, task & attributes management, project calendars, project calendar exceptions, and much more. 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), import the project from the database with a specified connection string or import the project from Project Online.

To further facilitate our customers, we have created programming language-specific SDKs. So you can select the SDK of your choice and process Microsoft Project (MPT, MPP, MPX) and Primavera P6 (XER, XML) file formats. In this article, we are going to discuss the usage of Aspose.Tasks Cloud SDK for .NET.

Installation

The first step in using the Cloud SDK is its installation. It is available for download at NuGet and GitHub. We recommend executing 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
Aspose.Tasks installed
Image 1:- Package installation using NuGet Package Manager.

Visual Studio Installation

We can also directly add the Cloud SDK reference inside Visual Studio solution:

  1. Open the Solution Explorer.
  2. Expand the project and Right-click Packages folder within your solution.
  3. Select Manage NuGet Packages… option
  4. Click on the Browse tab and search for “Aspose.Tasks-Cloud“.
  5. Click on the Aspose.Tasks-Cloud package, select the appropriate version in the right-tab and click Add Package button
Image 2:- Aspose.Tasks-Cloud in Visual Studio 2022.

Free Cloud subscription

Once the SDK is installed, the step is to create a free subscription account by visiting Aspose.Cloud dashboard. No credit card or other payment details are required and perform up to 150 Free document processing requests.

For account subscription, use your GitHub or Google account to simply Sign Up or, click on the Create a new Account button and provide the required information. Now login to the dashboard using credentials and expand the Applications section from the dashboard and scroll down towards the Client Credentials section to see Client ID and Client Secret details.

Client Credentials
Image 3:- Client Credentials at Aspose.Cloud dashboard.

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 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 filename and Stream instance containing MPP content
  • Call the UploadFile(…) method of TasksApi to upload 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 last step is saved in Stream instnace, we need to use File.Create object to save the output on 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

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 explained some amazing features of Aspose.Tasks Cloud API. Specifically, we have discussed the steps on how we can upload MPP file to Cloud storage and convert it into XML format. We have also explored the usage of .NET Cloud SDK to perform the conversion using the C# .NET code snippet. Furthermore, please note that all our Cloud SDKs are developed under MIT license, so their complete code snippet can be found over GitHub. In case you encounter any issue while using the API or you have any related query, please feel free to contact through the Free Product support forum.

Related articles

We also recommend visiting the following links to learn more about