I’m looking for a way to read and write an MPP file using Aspose.Task. It needs to sync data eg. PercentComplete with a database.
Currently I am able to read the first 5 collums (see image above for more details) like task.Get(Tsk.Name), task.Get(Tsk.ActualStart), … but not the last 4.
How to read the Resource Names (hidden in the image for privacy purposes) for each task in collector.Tasks?
How to read and write customs fields eg. ADMIND_ID, DEVOPS_ID, DEV_HOURS?
Many thanks in advance!
current code so far:
`
// Load MPP file
Project project = new Project(_datadir + “Example.mpp”);
// Load all tasks
TaskCollection allTasks = project.RootTask.Children;
// Loop through each task and read information related to tasks
foreach (Task task in allTasks)
{
Console.WriteLine("Reading Task " + task.Get(Tsk.Name));
Console.WriteLine("\nID: " + task.Get(Tsk.Id));
Console.WriteLine("Start: " + task.Get(Tsk.Start));
Console.WriteLine("Finish: " + task.Get(Tsk.Finish));
Console.WriteLine("\n===========================\n");
}
// Create a ChildTasksCollector instance
ChildTasksCollector collector = new ChildTasksCollector();
// Collect all the tasks from RootTask using TaskUtils
TaskUtils.Apply(project.RootTask, collector, 0);
#region Loop Tasks & resources
//Parse through all the collected tasks
foreach (Task task in collector.Tasks)
{
Console.WriteLine("Task Name : " + task.Get(Tsk.Name));
Console.WriteLine("Actual Work: " + task.Get(Tsk.Work).ToString());
Console.WriteLine("Actual PercentComplete: " + task.Get(Tsk.PercentComplete));
Console.WriteLine("Actual Start: " + task.Get(Tsk.ActualStart).ToLongDateString());
Console.WriteLine("Actual Finish: " + task.Get(Tsk.ActualFinish).ToLongDateString());
Console.WriteLine("Resource Name: ");
Console.WriteLine("ADMIND ID: ");
Console.WriteLine("DEVOPS ID: ");
Console.WriteLine("DEV HOURS: ");
Console.WriteLine("---------------------------------------------");
}
I have observed the issue shared by you and request you to please share the source file that we may use on our end to investigate the issue further and helping you out.
I have worked with sample project shared by you. Actually, every task has got Resource Name collection. So, you have to get that using Assignments collection. Secondly, the custom columns are available separately in task ExtendedAttribute collection. So, you need to check for extended attributes too and printing their respective values. In the following sample code, I have provided the example that fulfills all of your requirements.
public static void ReadProperties()
{
String _datadir = @"C:\Aspose Data\Project file\";
// Load MPP file
Project project = new Project(_datadir + "02_20OS-CM ECCO Crohn.mpp");
// Load all tasks
TaskCollection allTasks = project.RootTask.Children;
// Loop through each task and read information related to tasks
foreach (Aspose.Tasks.Task task in allTasks)
{
Console.WriteLine("Reading Task " + task.Get(Tsk.Name));
Console.WriteLine("\nID: " + task.Get(Tsk.Id));
Console.WriteLine("Start: " + task.Get(Tsk.Start));
Console.WriteLine("Finish: " + task.Get(Tsk.Finish));
Console.WriteLine("\n===========================\n");
}
// Create a ChildTasksCollector instance
ChildTasksCollector collector = new ChildTasksCollector();
// Collect all the tasks from RootTask using TaskUtils
TaskUtils.Apply(project.RootTask, collector, 0);
//#region
//Loop Tasks & resources
//Parse through all the collected tasks
foreach (Aspose.Tasks.Task task in collector.Tasks)
{
var ass = task.Assignments;
var bas = task.Baselines;
Console.WriteLine("Task Name : " + task.Get(Tsk.Name));
Console.WriteLine("Actual Work: " + task.Get(Tsk.Work).ToString());
Console.WriteLine("Actual PercentComplete: " + task.Get(Tsk.PercentComplete));
Console.WriteLine("Actual Start: " + task.Get(Tsk.ActualStart).ToLongDateString());
Console.WriteLine("Actual Finish: " + task.Get(Tsk.ActualFinish).ToLongDateString());
Console.WriteLine("Resource Name: ");
foreach (ResourceAssignment Rassign in task.Assignments)
{
Console.WriteLine(Rassign.Get(Asn.Resource).Get(Rsc.Name) );
}
var extendedAttributed= task.ExtendedAttributes;
foreach (var attrib in extendedAttributed)
{
if( attrib.AttributeDefinition.CfType==CustomFieldType.Number)
Console.WriteLine(String.Format("{0} : {1}", attrib.AttributeDefinition.Alias, attrib.NumericValue));
else
Console.WriteLine(String.Format("{0} : {1}", attrib.AttributeDefinition.Alias, attrib.TextValue));
}
Console.WriteLine("---------------------------------------------");
}
}