Retrieving Task's Budget Work and Cost Values
Contents
[
Hide
Show
]In Microsoft Project 2007 and later, tasks can have budget work and budget cost fields. With Aspose.Tasks for .NET, these values are available directly through the Tsk.BudgetWork and Tsk.BudgetCost fields.
Understanding Budget Work and Cost
- Budget Work represents the total planned work for a task in terms of hours or effort.
- Budget Cost represents the total planned monetary cost for a task.
Before Aspose.Tasks 5.0.0, developers had to calculate these values manually by summing the resource assignments. Now, they can be accessed directly from the task’s properties.
Example: Reading Budget Work and Cost
The following code example demonstrates how to retrieve a task’s BudgetWork and BudgetCost:
1Project project = new Project("New Project.mpp");
2
3// Display budget work and budget cost for project summary task
4Task projSummary = project.RootTask;
5Console.WriteLine("projSummary.BudgetWork = " + projSummary.Get(Tsk.BudgetWork).ToString());
6Console.WriteLine("projSummary.BudgetCost = " + projSummary.Get(Tsk.BudgetCost).ToString());
7
8// Display resource budget work
9Resource resource = project.Resources.GetByUid(6);
10Console.WriteLine("Resource BudgetWork = " + resource.Get(Rsc.BudgetWork).ToString());
11
12// Display resource budget cost
13resource = project.Resources.GetByUid(7);
14Console.WriteLine("Resource BudgetCost = " + resource.Get(Rsc.BudgetCost).ToString());
15
16// Display assignment budget work and budget cost
17foreach (ResourceAssignment assignment in projSummary.Assignments)
18{
19 if (assignment.Get(Asn.Resource).Get(Rsc.Type) == ResourceType.Work)
20 Console.WriteLine("Assignment BudgetWork = " + assignment.Get(Asn.BudgetWork).ToString());
21 else
22 Console.WriteLine("Assignment BudgetCost = " + assignment.Get(Asn.BudgetCost).ToString());
23}Key Notes
- Budget fields are only available in Microsoft Project 2007 and newer versions.
- Budget Work is usually expressed in hours (e.g., 120h).
- Budget Cost is expressed in the project’s currency (e.g., USD).
- These values help in comparing planned vs. actual costs during project tracking.
- Aspose.Tasks provides consistent access to these fields across MPP and XML formats.
FAQ
Q: Can I set Budget Work and Budget Cost values programmatically?
- Yes. These fields can be both read and updated using Aspose.Tasks.
Q: Do budget values depend on resource assignments?
- No. Unlike regular work and cost fields, budget fields are entered directly at the task level.
Q: Are budget fields supported in all Microsoft Project file formats?
- They are supported in MPP (2007 and above) and XML formats that include budget definitions.