Working with WBS Associated with a Task
WBS (Work Breakdown Structure) codes let you assign outline numbers to tasks according to the needs of your business. They provide a customized outline scheme for structuring and analyzing a project. Aspose.Tasks for .NET fully supports working with WBS values programmatically.
Working with Work Breakdown Structure (WBS) in Aspose.Tasks for .NET
In Microsoft Project, the Work Breakdown Structure (WBS) is a hierarchical outline that defines the structure of tasks within a project. It helps project managers organize, identify, and track project deliverables. Aspose.Tasks for .NET provides full support for working with WBS values programmatically. You can use the following properties of the Tsk class:
- WBS – returns or sets the full hierarchical WBS code of a task (e.g., 1.2.3).
- WBSLevel – returns or sets the depth (level) of the task within the WBS hierarchy.
These properties allow developers to read and update task structures when processing Microsoft Project files (MPP/XML).
Viewing WBS in Microsoft Project
To view WBS information in Microsoft Project:
- Open the Task Entry form.
- On the Insert menu, select Column.
- Add the WBS column to display task WBS values.
Example: Reading Task WBS
The following example shows how to get a task’s WBS value using Aspose.Tasks:
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.Get(Tsk.WBS));
13 Console.WriteLine(task.Get(Tsk.WBSLevel));
14
15 // Set custom WBS
16 task.Set(Tsk.WBS, "custom wbs" + task.Get(Tsk.WBS));
17}
Example: Adding WBS Code Definitions
Aspose.Tasks for .NET allows defining custom WBS code rules using the WBSCodeDefinition
class. This enables generating structured WBS codes similar to Microsoft Project.
1Project proj = new Project();
2
3proj.WBSCodeDefinition = new WBSCodeDefinition();
4proj.WBSCodeDefinition.GenerateWBSCode = true;
5proj.WBSCodeDefinition.VerifyUniqueness = true;
6proj.WBSCodeDefinition.CodePrefix = "CRS-";
7
8WBSCodeMask mask = new WBSCodeMask();
9mask.Length = 2;
10mask.Separator = "-";
11mask.Sequence = WBSSequence.OrderedNumbers;
12proj.WBSCodeDefinition.CodeMaskCollection.Add(mask);
13
14mask = new WBSCodeMask();
15mask.Length = 1;
16mask.Separator = "-";
17mask.Sequence = WBSSequence.OrderedUppercaseLetters;
18proj.WBSCodeDefinition.CodeMaskCollection.Add(mask);
19
20Task task = proj.RootTask.Children.Add("Task 1");
21Task child = task.Children.Add("Task 2");
22
23proj.Recalculate();
24proj.Save("AddWBSCodes_out.xml", SaveFileFormat.XML);
Example: Renumbering WBS Codes
Just like Microsoft Project provides the Renumber function, Aspose.Tasks for .NET can also renumber WBS codes programmatically:
1Project project = new Project("New Project.mpp");
2
3Console.WriteLine("WBS codes before: ");
4
5// output: ""; "1"; "2"; "4"
6foreach (Task task in project.RootTask.SelectAllChildTasks())
7{
8 Console.WriteLine("\"" + task.Get(Tsk.WBS) + "\"" + "; ");
9}
10
11project.RenumberWBSCode(new List<int> { 1, 2, 3 });
12// project.RenumberWBSCode(); // this overload can be used instead
13
14Console.WriteLine("WBS codes after: ");
15
16// output: ""; "1"; "2"; "3"
17foreach (Task task in project.RootTask.SelectAllChildTasks())
18{
19 Console.WriteLine("\"" + task.Get(Tsk.WBS) + "\"" + "; ");
20}
Key Notes
- WBS codes provide a hierarchical view of project tasks.
- You can read, assign, and customize WBS codes with Aspose.Tasks.
- The
WBSCodeDefinition
class gives fine control over WBS formatting and structure. - WBS codes can be renumbered programmatically to maintain consistency.
- Supported for both MPP and XML formats.
FAQ
Q: Can I define a custom WBS code pattern?
- Yes. Use the
WBSCodeDefinition
class to create custom rules.
Q: How is WBS different from task outline numbers?
- Outline numbers are system-generated, while WBS codes can be customized to match business rules.
Q: Can WBS codes be changed after task creation?
- Yes. WBS values can be updated or renumbered at any time.
Q: Does renumbering overwrite existing custom codes?
- Yes. Renumbering regenerates WBS codes according to the defined scheme.