Reading columns

Hi Team,

Thanks for your responses !!!

I want to read few new columns i.e.
· Successor,

· Milestone

· % Complete

P Please let me know a way to read and write this.

Thanks

Abhishek Prasad

Hi Abhishek,

Thank you for writing to us again.

Please give a try to the following sample code which displays the required information.


For writing please use following sample code:



Project proj = new Project(“Project1.mpp”);
foreach (TaskLink link in proj.TaskLinks)
{
Console.WriteLine("Task Id = " + link.PredTask.Get(Tsk.Id) + ", Successors = " + link.SuccTask.Get(Tsk.Id));
}

ChildTasksCollector collector = new ChildTasksCollector(); // Create a ChildTasksCollector instance
TaskUtils.Apply(proj.RootTask, collector, 0); // Collect all the tasks from RootTask using TaskUtils
foreach (Task tsk in collector.Tasks)
{
if(tsk.Get(Tsk.Id) != 0)
Console.WriteLine(“Task Id = " + tsk.Get(Tsk.Id) + " ,”
+ ", Is MileStone = " + tsk.Get(Tsk.IsMilestone).Value
+ ", %Complete = " + tsk.Get(Tsk.PercentComplete));
}


For writing please use following sample code:

Project proj = new Project(@“Blank2010.mpp”);
Task task1 = proj.RootTask.Children.Add(“Task 1”);
task1.Set(Tsk.Start, new DateTime(2016, 8, 3, 8 ,0,0));
task1.Set(Tsk.Duration, proj.GetDuration(8,TimeUnitType.Hour));
task1.Set(Tsk.IsMilestone, true);
task1.Set(Tsk.ActualStart, new DateTime(2016, 8, 3, 8, 0, 0));
task1.Set(Tsk.ActualDuration, proj.GetDuration(8, TimeUnitType.Hour));
Task task2 = proj.RootTask.Children.Add(“Task 2”);
task2.Set(Tsk.Duration, proj.GetDuration(8, TimeUnitType.Hour));
task2.Set(Tsk.Start, new DateTime(2016, 8, 4, 8, 0, 0));
TaskLink link = proj.TaskLinks.Add(task1, task2);
proj.Recalculate();
proj.Save(“output.mpp”,SaveFileFormat.MPP);