WBS Associated with a Task

WBS (Work Breakdown Structure) codes, lets you assign outline numbers to tasks according to the needs of your business. It’s a method for applying a customized outline scheme to a project. Aspose.Tasks for .NET supports this feature.

Working with Work Breakdown Structure

The WBS and WBSLevel properties exposed by the Tsk class are used to read and write a tasks work breakdown structure.

Microsoft Project View of WBS

To view WBS information in Microsoft Project:

  1. On the Task Entry Form, select the Insert menu and then Column.
  2. Add the WBS column.

Getting WBS in Aspose.Tasks

The following examples show 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}

Adding WBS Code Definitions in Aspose.Tasks

Aspose.Tasks for .NET allows adding WBS code definition for tasks to a project same as Microsoft Project.WBSCodeDefinition class exposes various properties that can be used to generate desired WBS codes in a project. The following code sample demonstrates setting up WBS code definitions in a 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);

Renumber WBS Codes

Aspose.Tasks for .NET API is able to renumber WBS codes similar to MSP’s “Renumber” function.

 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}
Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.