Reading and Writing General Properties
In Microsoft Project, every task has general properties such as name, ID, UID, and start/finish dates that define its identity and scheduling. With Aspose.Tasks for .NET, developers can easily read and write these properties programmatically when working with MPP or XML project files.
General Properties
The static class
Tsk provides access to all general properties of a
Task. These properties can be retrieved or modified using the Get
and Set
methods of the Task class.
Commonly used fields include:
Tsk.Name Type: String Purpose: Defines the task’s name.
Tsk.Id Type: Integer Purpose: A sequential ID assigned within the project.
Tsk.Uid Type: Integer Purpose: A unique identifier for the task that does not change when tasks are reordered.
Tsk.Start Type: DateTime Purpose: The planned start date of the task.
Tsk.Finish Type: DateTime Purpose: The planned finish date of the task.
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.
Example: Setting General Properties
The following C# example demonstrates how to assign values to general task 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");
Example: Reading General Properties
You can retrieve task properties by iterating through the children of the project’s RootTask:
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}
Key Notes
- ID is project-specific and may change if tasks are rearranged.
- UID is unique and remains stable across operations, making it useful for integration.
- Start and Finish dates define scheduling constraints and dependencies.
- Aspose.Tasks ensures consistent handling of these properties across MPP and XML formats.
FAQ
Q: What is the difference between ID and UID?
- ID is the sequential number of a task in the current project view, UID is a permanent unique identifier that does not change.
Q: Can I update both Start and Finish dates directly?
- Yes, but the final schedule may also depend on constraints and dependencies defined in the project.
Q: Does Aspose.Tasks support reading these properties from both MPP and XML files?
- Yes. General properties are consistently available for both formats.