Microsoft Project MPP File Update

Skip to end of metadata
Go to start of metadata
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 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);
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.