Microsoft Project MPP File Update

With Aspose.Tasks it is possible to update Microsoft Project 2010 MPP files in addition to XML. You can save the updated data to an existing or a new file.

Updating Microsoft Project MPP Files The following examples show how to add a new task to an existing Microsoft Project 2010 file and save it back to the same file. The code goes through the following steps:

  1. Create an instance of the project reader.
  2. Read the file.
  3. Create a task.
  4. Add the task to the project.
  5. Re-calculate.
  6. Save.

The code snippet shows the code first in Java to update the MPP file.

 1// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
 2// The path to the documents directory.
 3String dataDir = Utils.getDataDir(MppFileUpdate.class);
 4
 5long OneSec = 10000000;// microsecond * 10
 6long OneMin = 60 * OneSec;
 7long OneHour = 60 * OneMin;
 8
 9// Read an existing project
10Project project = new Project(dataDir + "SampleMSP2010.mpp");
11
12// create a new task
13Task task = project.getRootTask().getChildren().add("Task1");
14// set start date
15java.util.Calendar cal = java.util.Calendar.getInstance();
16
17cal.set(2012, 7, 1, 8, 0, 0);
18task.set(Tsk.START, cal.getTime());
19
20cal.set(2012, 7, 1, 17, 0, 0);
21task.set(Tsk.FINISH, cal.getTime());
22
23// Save the project as MPP project file
24project.save(dataDir + "AfterLinking.Mpp", SaveFileFormat.MPP);
25// Display result of conversion.
26System.out.println("Process completed Successfully");
Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.