views:

7

answers:

0

Hi,

I'm trying to use Interop.MSProject with C# to do something that conceptually, should be the simiplest thing in the world to do. However, I am having some trouble with it's cryptic api which has minimal documentation. All I wish to do is to find a row that contains a specific string in one of it's columns (cell) and remove that row. After I've done that, I just want to display the modified project file so that the user has the option to save it. Here is what I've tried:

MSProject.Application app = new MSProject.Application();
app.FileOpenEx(
    filePath,
    false,
    Type.Missing,
    Type.Missing,
    Type.Missing,
    Type.Missing,
    Type.Missing,
    Type.Missing,
    Type.Missing,
    Type.Missing,
    Type.Missing,
    MSProject.PjPoolOpen.pjPoolReadWrite,
    Type.Missing,
    Type.Missing,
    Type.Missing,
    Type.Missing,
    Type.Missing);

foreach(MSProject.Task task in proj.Tasks)
{
    if (task == null) continue;
    string cellValue = task.OutlineCode3;
    if (cellValue == searchString)
       task.Delete();
}  

app.Visible = true;

It seems as though task.Delete is not working. I've even tried to generalize this code to the following:

foreach (MSProject.Task task in proj.Tasks)
   task.Delete()

and this did not work either. Does anyone know a way that I can remove a task or a row base on a value in one of the rows cells?