Reading and Writing General Properties
Contents
[
Hide
Show
]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 static class Tsk contains all the properties related to a Task and can be get or set using the Get and Set methods exposed by Task. Some of the commonly used properties are as follow:
- Name, used to set and get a task’s name (string).
- Id, used to set and get a task’s ID (integer).
- Uid, used to set and get a task’s unique ID (integer).
- Start, used to set and get a task’s start date (DateTime).
- Finish, used to set and get a task’s end date (DateTime).
To view a task’s general properties in Microsoft Project:
- Open a project.
- On the View menu, select More Views and then Task Entry to open the task entry form.
- From the Insert menu, select Column and add the ID and Unique ID.
Setting General Properties
The below code sample shows you, how to set general properties.
1Project project = new Project();
2
3// Add task and set task properties
4Task task = project.RootTask.Children.Add("Task1");
5task.Set(Tsk.Start, project.RootTask.Get(Tsk.Start).AddDays(1));
6task.Set(Tsk.Name, "new name");
Getting General Properties
Get a task’s properties by traversing the children of the project’s RootTask property.
1Project project = new Project("New Project.mpp");
2
3// Create a ChildTasksCollector instance
4ChildTasksCollector collector = new ChildTasksCollector();
5
6// Collect all the tasks from RootTask using TaskUtils
7TaskUtils.Apply(project.RootTask, collector, 0);
8
9// Parse through all the collected tasks
10foreach (Task task in collector.Tasks)
11{
12 Console.WriteLine("Task Id: {0}", task.Get(Tsk.Id));
13 Console.WriteLine("Task Uid: {0}", task.Get(Tsk.Uid));
14 Console.WriteLine("Task Name: {0}", task.Get(Tsk.Name));
15 Console.WriteLine("Task Start: {0}", task.Get(Tsk.Start));
16 Console.WriteLine("Task Finish: {0}", task.Get(Tsk.Finish));
17}