this is my first question on the site although I have gotten lots of help from it already.
What I am looking to do is to open a MSProject (.MPP) document and look through all the task names, then only retrieve the ones with a specified name.
I have found a bit of code on this site NerdyHearn which seems to suit my needs, but for some reason I can only retrieve the name of the absolute first task? Which seems strange to me since this line of code here:
foreach (Microsoft.Office.Interop.MSProject.Task task in proj.Tasks)
{
}
Is a loop right? I have tried with different .MPP files and even created my own, but it still only retrieves the first one.
And if someone can help me to design a filter to use when retrieving the task names that would be great!
I have also tried to find documentation for Microsoft.Office.Interop.MSProject but I really can't seem to find it.
Posting the code block so that you see what I have. Please post a file if you could, perhaps its something else instead of subtasks as I have 4 levels in some spots and all my tasks come out as expected.
using Microsoft.Office.Interop.MSProject;
using System;
using System.Reflection;
namespace PProject
{
public class Program
{
public static void Main()
{
Application projApp = new Application();
projApp.FileOpenEx(@"C:\Tickets.mpp", true, Missing.Value,
Missing.Value, Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value, Missing.Value,
PjPoolOpen.pjDoNotOpenPool, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value);
Project proj = projApp.ActiveProject;
// Enumerate the tasks
foreach (Task task in proj.Tasks)
{
string name = task.Name;
Console.WriteLine(task.Name);
}
// Make sure to clean up and close the file
projApp.FileCloseAll(PjSaveType.pjDoNotSave);
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With