Importing Project Active Tasks

I've been using aspose.tasks for 3 days so please be gentle:

Goal: Pull the fields that are currently in use in Microsoft Project

For example: I'm the project manager and use task ID, duration, start and finish dates, and a custom fielded name "Lenny" in Microsoft Project;

I only want to pull back these five fields. Can I do this? If so, would you be willing to share your thoughts (sample code would be great).

Thanks in advance

Len

Hi Len,

Thanks for considering Aspose. Please check Aspose.Total for .NET|Documentation for reading general properties (ID, Start and Finish etc.), Aspose.Total for .NET|Documentation for reading custom fields and Aspose.Total for .NET|Documentation for duration calculation (in days, hours or minutes).

I have combined the code from above mentioned topics in the following example to read your required fields.

static void Main(string[] args)
{
    try
    {
        Aspose.Tasks.License lic = new License();
        lic.SetLicense(@"Aspose.Total.Product.Family.lic");
        ProjectReader reader = new ProjectReader();
        Project project = reader.Read("Project3.mpp");
        ChildTasksCollector collector = new ChildTasksCollector();
        TaskUtils.Apply(project.RootTask, collector, 0);
        foreach (Task task in collector.Tasks)
        {
            Console.WriteLine("\nID: " + task.Id +
                              "\nName: " + task.Name +
                              "\nStart: " + task.Start +
                              "\nFinish: " + task.Finish +
                              "\nDuration: " + CalculateDuration(task.Start, task.Finish,
                                  (task.Calendar != null) ? task.Calendar : project.Calendar));
            foreach (ExtendedAttribute extendedAttribute in task.ExtendedAttribute)
            {
                Console.WriteLine(extendedAttribute.AttributeDefinition.FieldName + " :" + extendedAttribute.Value);
            }
        }
    }
    catch (Exception ex)
    {
        Console.WriteLine(ex.Message);
    }
    Console.ReadLine();
}

static double CalculateDuration(DateTime startDate, DateTime endDate, Aspose.Tasks.Calendar taskCalendar)
{
    DateTime tempDate = startDate;
    TimeSpan timeSpan;
    //Get Duration in Days
    double durationInDays = 0;
    while (tempDate < endDate)
    {
        if (taskCalendar.IsDayWorking(tempDate))
        {
            timeSpan = taskCalendar.GetWorkingHours(tempDate);
            if (timeSpan.TotalHours > 0)
                durationInDays = durationInDays + timeSpan.TotalDays * (24 / (timeSpan.TotalHours));
        }
        tempDate = tempDate.AddDays(1);
    }
    tempDate = startDate;
    return durationInDays;
}

Please feel free to contact us in case you have further comments or questions.

Best Regards,

Thank you for your leadership and most importantly your kindness with providing the sample code.

May your day be blessed with all that is good