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.

Billboard image

Monitor more than uptime.

With Checkly, you can use Playwright tests and Javascript to monitor end-to-end scenarios in your NextJS, Astro, Remix, or other application.

Get started now!

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Engage with a sea of insights in this enlightening article, highly esteemed within the encouraging DEV Community. Programmers of every skill level are invited to participate and enrich our shared knowledge.

A simple "thank you" can uplift someone's spirits. Express your appreciation in the comments section!

On DEV, sharing knowledge smooths our journey and strengthens our community bonds. Found this useful? A brief thank you to the author can mean a lot.

Okay