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.