| 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:
- Create an instance of the project reader.
- Read the file.
- Create a task.
- Add the task to the project.
- Re-calculate.
- Save.
The code snippet shows the code first in Java to update MPP file.
Code Sample
Java
long OneSec = 10000000;//microsecond * 10 long OneMin = 60 * OneSec; long OneHour = 60 * OneMin; try { // Set license. Provide full path and license file name com.aspose.tasks.License licTask = new com.aspose.tasks.License(); licTask.setLicense("E:\\Aspose.Total.Product.Family.lic"); } catch(Exception ex) { System.out.println(ex.getMessage()); } // Open a project Project project = new Project("Blank2010.mpp"); // Create a new task Task tskADD = new Task("Task 1"); java.util.Calendar cal = java.util.Calendar.getInstance(); cal.set(2012, 7, 1, 8, 0,0); tskADD.setStart(cal.getTime()); cal.set(2012, 7, 1, 17, 0, 0); tskADD.setFinish(cal.getTime()); tskADD.setDuration((long) (OneHour * 8.0)); // Add the task to the root of the project project.getRootTask().getChildren().add(tskADD); // Perform calculations project.calcTaskIds(); project.calcTaskUids(); // Save the project as MPP project file project.save("AfterLinking.Mpp", SaveFileFormat.MPP);

