DEV Community

panchenko-dm-aspose
panchenko-dm-aspose

Posted on • Edited on

4 1

Modify MS Project files in TypeScript or JavaScript using Aspose.Tasks Cloud API.

Aspose.Tasks Cloud is a REST API for manipulating and converting Microsoft Project (MPP, XML, etc.) and Oracle Primavera (XER) documents. It allows you to work with all aspects of a project as well as offers a wide range of export options allowing developers to convert supported project formats to a number of industry-standard formats (PDF/Excel/Images).
Our Cloud SDKs are wrappers around REST API in various programming languages (PHP, Python, Node.js), allowing you to work with MS Project/Oracle Primavera documents in the language of your choice quickly and easily, gaining all benefits of strong types and IDE highlights.
Before we get started, I want to say a few words about legal use Aspose.Tasks Cloud API. For receiving successful responses from the server, you need to sign up for free on https://id.containerize.com/signup so you can get your own App SID and App Key.
These credentials will be used in a further example. We also will use 'fs' module for read\write files, but you can use whatever is more convenient for you. After you get SID and Key for your app, we will need to install SDK package, just like that:

npm i @asposecloud/aspose-tasks-cloud

When it's done, let's create an instance of Tasks.Api:

const tasksApi = new TasksApi("Your AppSid here", "Your AppKey here");
// Then we need to upload our MS project file to the server for the further actions:
const fileName = "Project2016.mpp";
const localPath = "./" + fileName;
const buffer = fs.readFileSync(localPath);
const uploadFileRequest :UploadFileRequest = {path: fileName, file: buffer, storageName: ''};
tasksApi.uploadFile(uploadFileRequest).then(uploadResult => {
//here will be further actions
});
view raw UploadFile.js hosted with ❤ by GitHub

Good! Now we can do whatever we want with our project. Let's add a new task:

const postRequest = new PostTaskRequest();
postRequest.name = fileName;
postRequest.taskName = "Some new task";
tasksApi.postTask(postRequest).then(postTaskResult => {
//here will be further actions
});
view raw AddTasks.js hosted with ❤ by GitHub

Simple isn't it?. Now let's look at the result:

const downloadFileRequest: DownloadFileRequest = { path: fileName, storageName: '', versionId: '' };
tasksApi.downloadFile(downloadFileRequest).then(fileResult => {
fs.writeFileSync("./newOne.mpp", fileResult.body)
})
view raw DownloadFile.js hosted with ❤ by GitHub

Well, that's it. We just tested adding tasks to the project file. But what if you want to add, modify, delete or take calendar from your project? Or do some stuff with your assignments? Or deal with some another part of the project? SDK source code contains a large number of use cases which you can see here.
I hope you enjoy using this tool to manipulate your MS project files.

Top comments (0)

SurveyJS custom survey software

JavaScript Form Builder UI Component

Generate dynamic JSON-driven forms directly in your JavaScript app (Angular, React, Vue.js, jQuery) with a fully customizable drag-and-drop form builder. Easily integrate with any backend system and retain full ownership over your data, with no user or form submission limits.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay