-
Couldn't load subscription status.
- Fork 1
Reading the Critical Path
ZeeshanShafqat edited this page Jan 24, 2014
·
3 revisions
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.
//Create Application object
Application projectApplication = new MSProject.Application();
object missingValue = System.Reflection.Missing.Value;
//Open an MPP file
projectApplication.FileOpenEx("Project1.mpp",
missingValue, missingValue, missingValue, missingValue,
missingValue, missingValue, missingValue, missingValue,
missingValue, missingValue, PjPoolOpen.pjPoolReadOnly,
missingValue, missingValue, missingValue, missingValue,
missingValue);
//Create a Project object by assigning active project
Project project = projectApplication.ActiveProject;
// Enumerate the tasks
foreach (Task task in project.Tasks)
{
//Get critical tasks
if (task != null)
if ((bool)task.Critical)
{
Console.WriteLine(task.ID + " " + task.Name);
Console.WriteLine(task.Start);
Console.WriteLine(task.Finish + "\n");
}
}
// Make sure to clean up and close the file
projectApplication.FileCloseAll(PjSaveType.pjDoNotSave);
###Aspose.Tasks 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.
//Open project file
string fileName = "Project.mpp";
ProjectReader reader = new ProjectReader();
Project project = reader.Read(fileName);
// Get the critical path
ArrayList criticalPath = new ArrayList(project.GetCriticalPath());
// Enumerate the tasks in the critical path
foreach (Aspose.Tasks.Task task in criticalPath)
{
Console.WriteLine(task.Id + " " + task.Name);
Console.WriteLine(task.Start);
Console.WriteLine(task.Finish + "\n");
}
Download