MPP Export & Import Related

Hi Team,


1) I want to do the schema validation i.e need the column counts and names of the MPP fields & match the same with the column names coming from the XML.

2) I want to export the data to MPP. The data will come from the data base & I need to maintain the hierarchy while creating the parent child relationship in MPP. I am using a sample MPP template for export purpose.

3) I want to do the import of MPP Data to Database, in this case I need to read all the fields present in the MPP and Map the same to the database object.

The problem I faced in reading the column names is I am not getting the approch to do so.

The problem I am facing in case of Export is I am unable to map to the MPP sample.

The problem I am facing with Import is that I am unable to read all the columns present in the MPP.

Please help team ASAP.


Thanks in advance.




Regards
Abhishek




Hi Abhishek,

Thank you for contacting Aspose support tam again.

We can get all the available fields in a project file using following sample code.

String path = url + "Tasks_755164";
Project proj = new Project(path + "Sample.mpp");
ChildTasksCollector collector = new ChildTasksCollector(); // Create a ChildTasksCollector instance
TaskUtils.Apply(proj.RootTask, collector, 5); // Collect all the tasks from RootTask using TaskUtils
foreach (Task tsk in collector.Tasks)
{
    foreach (Table tbl in proj.Tables)
    {
        foreach (TableField field in tbl.TableFields)
        {
            switch (field.Field)
            {
                case Field.TaskID:
                {
                    Console.WriteLine("Task ID = " + tsk.Get(Tsk.Id));
                    break;
                }
                //Add more cases here
            }
            Console.WriteLine(field.Field.ToString());
        }
    }
}

For maintaining the hierarchy, you may please use one of the following sample code.

Sample 1:

Project asProject = new Project("Blank2010.mpp");
asProject.Set(Prj.StartDate, new DateTime(2004, 1, 1));
Task asTask = asProject.RootTask.Children.Add("Task1");
Task asTaskSub1 = asTask.Children.Add("Task1-sub1");
DateTime dateTaskSub1 = new DateTime(2004, 1, 5, 8, 0, 0);
asTaskSub1.Set(Tsk.Duration, asProject.GetDuration(8, TimeUnitType.Hour));
asTaskSub1.Set(Tsk.Start, dateTaskSub1);
Task asTaskSub2 = asTask.Children.Add("Task1-sub2");
DateTime dateTaskSub2 = new DateTime(2004, 1, 6, 8, 0, 0);//
asTaskSub2.Set(Tsk.Duration, asProject.GetDuration(32, TimeUnitType.Hour));
asTaskSub2.Set(Tsk.Start, dateTaskSub2);
asProject.Recalculate();
asProject.Save("output.xml", SaveFileFormat.XML);
asProject.Save("output.mpp", SaveFileFormat.MPP);

Sample 2:

Project asProject = new Project("Blank2010.mpp");
asProject.Set(Prj.StartDate, new DateTime(2004, 1, 1));
Task asTask = asProject.RootTask.Children.Add("Task1");
Task asTaskSub1 = asProject.RootTask.Children.Add("Task1-sub1");
DateTime dateTaskSub1 = new DateTime(2004, 1, 5, 8, 0, 0);
asTaskSub1.Set(Tsk.Duration, asProject.GetDuration(8, TimeUnitType.Hour));
asTaskSub1.Set(Tsk.Start, dateTaskSub1);
asTaskSub1.OutlineIndent();
Task asTaskSub2 = asProject.RootTask.Children.Add("Task1-sub2");
DateTime dateTaskSub2 = new DateTime(2004, 1, 6, 8, 0, 0);
asTaskSub2.Set(Tsk.Duration, asProject.GetDuration(32, TimeUnitType.Hour));
asTaskSub2.Set(Tsk.Start, dateTaskSub2);
asTaskSub2.OutlineIndent();
asProject.Recalculate();
asProject.Save("D:/Aspose_JavaProjects/Task/Tasks_748750/output.xml", SaveFileFormat.XML);
asProject.Save("D:/Aspose_JavaProjects/Task/Tasks_748750/output.mpp", SaveFileFormat.MPP);

Aspose.Tasks does not provide direct support for databases, therefore you may please use your own logic to import/export data from databases.