Reading Tasks and Resources
While working with MPP files, you might need to read tasks and resources from your project. This article provides a practical overview of how to read project data using both VSTO and Aspose.Tasks for .NET.
Introduction
Reading tasks and resources is often the first step in building project analytics, generating reports, or validating project integrity. With Microsoft Project files (MPP), this can be achieved using either:
- VSTO (Visual Studio Tools for Office) — requires Microsoft Project and COM interop.
- Aspose.Tasks for .NET — a standalone API for working with project data without relying on Microsoft Project.
This article outlines how to extract task and resource information in both approaches.
Read Tasks and Resources Using VSTO
To access task and resource data using VSTO:
- Create a new project in Visual Studio.
- Add a reference to Microsoft Project 12.0 Object Library from the COM tab.
- Import the
Microsoft.Office.Interop.MSProject
namespace. - Use the following sample code.
1// Create Application object
2Application projectApplication = new ApplicationClass();
3object missingValue = System.Reflection.Missing.Value;
4
5// Open MPP file
6projectApplication.FileOpenEx(@"C:\Project1.mpp",
7 missingValue, missingValue, missingValue, missingValue,
8 missingValue, missingValue, missingValue, missingValue,
9 missingValue, missingValue, PjPoolOpen.pjPoolReadOnly,
10 missingValue, missingValue, missingValue, missingValue,
11 missingValue);
12
13Project project = projectApplication.ActiveProject;
14
15// Read all tasks
16foreach (Task task in project.Tasks)
17{
18 Console.WriteLine("Reading Task: " + task.Name);
19 Console.WriteLine("ID: " + task.ID);
20 Console.WriteLine("Start: " + task.Start);
21 Console.WriteLine("Finish: " + task.Finish);
22 Console.WriteLine("===========================\n");
23}
24
25// Read all resources
26foreach (Resource resource in project.Resources)
27{
28 string resourceType = resource.Type switch
29 {
30 PjResourceTypes.pjResourceTypeCost => "Cost",
31 PjResourceTypes.pjResourceTypeMaterial => "Material",
32 PjResourceTypes.pjResourceTypeWork => "Work",
33 _ => "Unknown"
34 };
35
36 Console.WriteLine("Reading Resource: " + resource.Name);
37 Console.WriteLine("ID: " + resource.ID);
38 Console.WriteLine("Type: " + resourceType);
39 Console.WriteLine("===========================\n");
40}
41
42Console.ReadLine();
Notes
- Tasks and resources are accessed through
project.Tasks
andproject.Resources
. - Each resource’s type is identified using
PjResourceTypes
. - VSTO depends on Microsoft Project being installed and available at runtime.
Read Tasks and Resources Using Aspose.Tasks for .NET
To achieve the same using Aspose.Tasks for .NET:
- Create a new Visual Studio project.
- Add a reference to Aspose.Tasks via the .NET tab.
- Import the
Aspose.Tasks
namespace. - Use the code example below.
1Project project = new Project("New Project.mpp");
2
3// Load all tasks
4TaskCollection allTasks = project.RootTask.Children;
5
6// Loop through each task and read information related to tasks
7foreach (Task task in allTasks)
8{
9 Console.WriteLine("Reading Task " + task.Get(Tsk.Name));
10 Console.WriteLine("ID: " + task.Get(Tsk.Id));
11 Console.WriteLine("Start: " + task.Get(Tsk.Start));
12 Console.WriteLine("Finish: " + task.Get(Tsk.Finish));
13}
14
15// Loop through each resource and read information related to resources
16foreach (Resource resource in project.Resources)
17{
18 string resourceType = null;
19 switch (resource.Get(Rsc.Type))
20 {
21 case ResourceType.Material:
22 resourceType = "Material";
23 break;
24 case ResourceType.Work:
25 resourceType = "Work";
26 break;
27 default:
28 resourceType = "Cost";
29 break;
30 }
31
32 Console.WriteLine("Reading Resource " + resource.Get(Rsc.Name));
33 Console.WriteLine("ID: " + resource.Get(Rsc.Id));
34 Console.WriteLine("Type: " + resourceType);
35}
Highlights
- The
Project
object provides access toRootTask.Children
for task traversal. - Resources are accessed via the
Resources
collection. - Aspose.Tasks also supports advanced features like calendars, extended attributes, and baselines — without Microsoft Project.
Comparison Table
Feature | VSTO / Interop | Aspose.Tasks for .NET |
---|---|---|
Requires Microsoft Project | ✅ Yes | ❌ No |
Platform | 🖥 Windows only | ✅ Cross-platform |
Access Model | COM-based | Pure .NET API |
Ease of Deployment | ⚠ Limited | ✅ Self-contained |
Reading Resources | project.Resources | project.Resources |
Reading Tasks | project.Tasks | project.RootTask.Children |
Summary
Extracting tasks and resources is a foundational capability when working with Microsoft Project files. While VSTO provides a way to work with Project files through COM interop, it suffers from limited deployment scenarios and platform restrictions.
Aspose.Tasks for .NET offers a lightweight, cross-platform, and maintainable alternative for reading and processing project data — making it ideal for modern enterprise applications and automation pipelines.
To continue exploring project data access with Aspose.Tasks, see: