Reading the Critical Path
The critical path is the series of tasks (or even a single task) that dictates the calculated finish date of the project. That is, when the last task in the critical path is completed, the project is completed.
By knowing and tracking the critical path for your project, as well as the resources assigned to critical tasks, you can determine which tasks can affect your project’s finish date and whether your project will finish on time.
If it’s important for your project to finish on schedule, pay close attention to the tasks on the critical path and the resources assigned to them. These elements determine whether your project will finish on time.
This article gives a small idea of how to load MPP files in your .NET applications and read the critical path or the tasks on the critical path from your projects using VSTO and Aspose.Tasks for .NET.
Read Critical Path Using VSTO
Following steps are required to accomplish this task:
- Create a new project in Visual Studio.
- In the Solution Explorer, right-click and select Add Reference, then select the COM components tab.
- Select the Microsoft Project 12.0 Object Library and then click OK. This imports the Microsoft.Office.Interop.MSProject namespace at the start of the code.
- Use the code from the following example to read critical tasks.
1// Create Application object
2Application projectApplication = new ApplicationClass();
3object missingValue = System.Reflection.Missing.Value;
4projectApplication.FileOpenEx(@"C:\Project1.mpp",
5 missingValue, missingValue, missingValue, missingValue,
6 missingValue, missingValue, missingValue, missingValue,
7 missingValue, missingValue, PjPoolOpen.pjPoolReadOnly,
8 missingValue, missingValue, missingValue, missingValue,
9 missingValue);
10Project project = projectApplication.ActiveProject;
11foreach (Task task in project.Tasks)
12{
13 // Get critical tasks
14 if (task != null)
15 {
16 if ((bool)task.Critical)
17 {
18 Console.WriteLine(task.ID + " " + task.Name);
19 Console.WriteLine(task.Start);
20 Console.WriteLine(task.Finish + "\n");
21 }
22 }
23}
24// Make sure to clean up and close the file
25projectApplication.FileCloseAll(PjSaveType.pjDoNotSave);
Read Critical Path Using Aspose.Tasks for .NET
The following steps are required to accomplish this task:
- Create a new project in Visual Studio.
- In the Solution Explorer, right-click and select Add Reference, then select the .NET tab.
- Select Aspose.Tasks and click OK. This imports the Aspose.Tasks namespace at the start of the code.
- Use the code from the following example to read tasks and resources.
1Project project = new Project("New Project.mpp");
2
3// Get the critical path
4TaskCollection criticalPath = project.CriticalPath;
5
6// Enumerate the tasks in the critical path
7foreach (Task task in criticalPath)
8{
9 Console.WriteLine(task.Get(Tsk.Id) + " " + task.Get(Tsk.Name));
10 Console.WriteLine(task.Get(Tsk.Start));
11 Console.WriteLine(task.Get(Tsk.Finish));
12}