Reading and Writing General Properties

Tasks can be identified by a number of general properties, such as name, ID, start and finish date. Aspose.Tasks can be used to get and set task properties when working with projects.

General Properties

The Task exposes several general properties:

To view a task’s general properties in Microsoft Project:

  1. Open a project.
  2. On the View menu, select More Views and then Task Entry to open the task entry form.
  3. From the Insert menu, select Column and add the ID and Unique ID as shown in the screenshot below.

Task general properties view in Microsoft Project

read and write general properties of Microsoft Project

Setting General Properties

To set the properties shown in the screenshot above, use the code below.

 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(ReadWriteGeneralProperties.class);
 4
 5Project project = new Project();
 6Task task = project.getRootTask().getChildren().add("Task1");
 7// Set task start date
 8java.util.Calendar cal = java.util.Calendar.getInstance();
 9cal.set(2013, 7, 17, 8, 0, 0);
10task.set(Tsk.START, cal.getTime());
11// Set task name
12task.set(Tsk.NAME, "new name");

Getting General Properties

Get a task’s properties by traversing the children of the project’s RootTask property.

 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(ReadWriteGeneralProperties.class);
 4
 5Project prj = new Project(dataDir + "project.mpp");
 6// Create a ChildTasksCollector instance
 7ChildTasksCollector collector = new ChildTasksCollector();
 8
 9// Collect all the tasks from RootTask using TaskUtils
10TaskUtils.apply(prj.getRootTask(), collector, 0);
11
12// Parse through all the collected tasks
13for (Task tsk : collector.getTasks()) {
14    System.out.println("Task Id:" + tsk.get(Tsk.ID));
15    System.out.println("Task Uid: " + tsk.get(Tsk.UID));
16    System.out.println("Task Name: " + tsk.get(Tsk.NAME));
17    System.out.println("Task Start: " + tsk.get(Tsk.START));
18    System.out.println("Task Finish: " + tsk.get(Tsk.FINISH));
19}
Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.