Hi, I have been searching online for some sample codes on how to correctly load and save a Microsoft Project file. After digging and some trials and errors, I stumbled upon the problem of saving the same MPP file I opened. I tried playing with the attributes, but to no avail. Here are the codes I used to play with:
object fileName = "C:\\Test.mpp";
object readOnly = false;
object missing = System.Reflection.Missing.Value;
Microsoft.Office.Interop.MSProject.PjMergeType merge = Microsoft.Office.Interop.MSProject.PjMergeType.pjDoNotMerge;
Microsoft.Office.Interop.MSProject.PjPoolOpen pool = Microsoft.Office.Interop.MSProject.PjPoolOpen.pjDoNotOpenPool;
object ignoreReadOnlyRecommended = false;
Microsoft.Office.Interop.MSProject.ApplicationClass appclass = new Microsoft.Office.Interop.MSProject.ApplicationClass();
appclass.FileOpen(fileName, readOnly, merge, missing, missing, missing, missing, missing, missing, missing, missing, pool, missing, missing, ignoreReadOnlyRecommended, missing);
appclass.Visible = false;
Microsoft.Office.Interop.MSProject.Project project = appclass.ActiveProject;
project.Resources.Add("A", 1);
project.Resources.Add("B", 2);
project.Resources.Add("C", 3);
project.Resources.Add("D", 4);
project.Resources.Add("E", 5);
Microsoft.Office.Interop.MSProject.Task task = project.Tasks.Add("Requirement Collection",missing);
task.Start = "08/1/2007";
task.Finish = "10/25/2007";
task.Assignments.Add(task.ID, 1, missing);
task.Assignments.Add(task.ID, 2, missing);
task.Milestone = true;
task.OutlineLevel = 2;
appclass.FileSave();
The problem occurs when I am trying to save. It opens up Microsoft Project and prompt me to save as instead. I just want it to let Microsoft Project out of it and quietly save. I notice that the file is opened as Read-Only even though I specified it to open not as Read-Only. I figure that I might be doing something wrong, but I have no idea what. Please point me what I am doing wrong.
By the way, I am using Microsoft Project 12.0 Object Library.
Also, how do I correctly attach a predecessor to a task?