We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

How to add Predecessor(Task Link) in export mpp file

Dear Omnath,

How can i add Predecessor(Task Link) in export mpp file

.i have store the data in datatable.Sample code:

ProjectReader readerMPP = new ProjectReader();

Project Exportproject = readerMPP.Read(EmptyTemplateFile);

Exportproject.RootTask.Children.Add(ParentRoot);

foreach (Task tsk in Exportproject.RootTask.Children)

{

DataRow dr = dt.AsEnumerable().Where(r => ((string)r["Predecessors"]) != "").First();

}

Exportproject.CalcTaskIds();


Exportproject.CalcTaskUids();


Exportproject.UpdateReferences();


Exportproject.Save(ExportFile, Aspose.Tasks.Saving.SaveFileFormat.MPP);

ProjectReader readerMPP = new ProjectReader();

Project Exportproject = readerMPP.Read(EmptyTemplateFile);

Exportproject.RootTask.Children.Add(ParentRoot);

foreach (Task tsk in Exportproject.RootTask.Children)

{

DataRow dr = dt.AsEnumerable().Where(r => ((string)r["Predecessors"]) != "").First();

}

Exportproject.CalcTaskIds();

Exportproject.CalcTaskUids();

Exportproject.UpdateReferences();

Exportproject.Save(ExportFile, Aspose.Tasks.Saving.

SaveFileFormat.MPP);

Hi Sankar,

I do not have extensive information on Aspose PDF. Also please post this question in new post so that experts / support team may easily answer you.

Hi Sankar,

a.sankar4:

Dear Omnath,

How can i add Predecessor(Task Link) in export mpp file

.i have store the data in datatable.Sample code:

ProjectReader readerMPP = new ProjectReader();

Project Exportproject = readerMPP.Read(EmptyTemplateFile);

Exportproject.RootTask.Children.Add(ParentRoot);

foreach (Task tsk in Exportproject.RootTask.Children)

{

DataRow dr = dt.AsEnumerable().Where(r => ((string)r["Predecessors"]) != "").First();

}

Exportproject.CalcTaskIds();


Exportproject.CalcTaskUids();


Exportproject.UpdateReferences();


Exportproject.Save(ExportFile, Aspose.Tasks.Saving.SaveFileFormat.MPP);

ProjectReader readerMPP = new ProjectReader();

Project Exportproject = readerMPP.Read(EmptyTemplateFile);

Exportproject.RootTask.Children.Add(ParentRoot);

foreach (Task tsk in Exportproject.RootTask.Children)

{

DataRow dr = dt.AsEnumerable().Where(r => ((string)r["Predecessors"]) != "").First();

}

Exportproject.CalcTaskIds();

Exportproject.CalcTaskUids();

Exportproject.UpdateReferences();

Exportproject.Save(ExportFile, Aspose.Tasks.Saving.

SaveFileFormat.MPP);


Thanks for your inquiry. You query pertains to Aspose.Tasks, so I am moving your post to related forum. My colleague from Aspose.Tasks will guide you appropriately.

Best Regards,

Hi Sankar,


I have tried to reproduce the scenario using above code but it could not be compiled. Also the template file and sample data is not available.

Following is a sample code which adds predecessors for the tasks in an existing MPP (attached as Project6.mpp). If this does not solve your issue, could you please send us a complete project which can be compiled and executed here along with the template files? It will help us to analyze the problem and provide assistance as soon as possible.


Project proj = new Project(@“Project6.mpp”);
TaskLink link = new TaskLink(proj.RootTask.Children[0], proj.RootTask.Children[1], TaskLinkType.FinishToStart);
proj.AddTaskLink(link);
link = new TaskLink(proj.RootTask.Children[1], proj.RootTask.Children[2], TaskLinkType.FinishToStart);
proj.AddTaskLink(link);
Task.Recalculate(proj.RootTask);
proj.Save(@“Project7.mpp”, SaveFileFormat.MPP);

kashif.iqbal ,

i have attached my sample project please find the file.

my problem is i was able to read all data include predecessor from MPP file and store into datatable. then create MPP file using datatable i was able fill all column except predecessor.

How can i fill predecessor value from datatable.

pelase do the needful.

Hi Sankar,


I have gone through the project and as it is quite a large code, it is difficult to sort out the issue. I am working to write some sample code which uses this data to create new MPP file with same information along with the predecessors. Please spare me little time to share my findings with you.


Hi Sankar,


I have observed following issues in your code:

  1. Child count is manually set which is not recommended.
  2. BaseLineStart and BaseLine Finish dates are wrong.
  3. PercentageComeplete is set manually whereas setting ActualStart and ActualFinish set this valaue automatically.
  4. Task Start, Finish and Duration are set manually however it is recommended that only start and duration be set, while Finish date be calculated by the library itself.
  5. Summary task start, finish duration etc. is set manually however it should also be calculated by the library.
  6. While setting the Predecessor of a task, name of the predecessor task is set instead of ID.

Here is a sample code which can be used as guide line to accomplish the task.

static public void CreateProject()
{
Project prj = new Project(@“D:\Aspose\Blank2010.mpp”);

//add working days Saturday and Sunday
WorkingTime wt1 = new WorkingTime();
wt1.FromTime = new DateTime(1, 1, 1, 8, 0, 0, 0);
wt1.ToTime = new DateTime(1, 1, 1, 12, 0, 0, 0);
WorkingTime wt2 = new WorkingTime();
wt2.FromTime = new DateTime(1, 1, 1, 13, 0, 0, 0);
wt2.ToTime = new DateTime(1, 1, 1, 17, 0, 0, 0);
prj.Calendars[0].Days[6].DayWorking = true;

//Saturday
prj.Calendars[0].Days[6].WorkingTimes.Add(wt1);
prj.Calendars[0].Days[6].WorkingTimes.Add(wt2);
prj.Calendars[0].Days[6].DayWorking = true;

//Sunday
prj.Calendars[0].Days[0].WorkingTimes.Add(wt1);
prj.Calendars[0].Days[0].WorkingTimes.Add(wt2);
prj.Calendars[0].Days[0].DayWorking = true;


List<string> ResourceNamesList = new List<string>(new string[] { “Mark”, “bob”, “Jcob” });
List ResourcesList = new List();
Aspose.Tasks.Task rootTask = prj.RootTask;
for (int i = 0; i <= 2; i++)
{
Resource res = GetTestResource(ResourceNamesList[i]);
prj.Resources.Add(res);
}

//Define Tasks
List<string> SummaryNamesList = new List<string>(new string[] { “Activity 1”, “Activity 2”, “Activity 3” });
List<string> TaskNamesList = new List<string>(new string[] { “Task 1”, “Task 2”, “Task 3” });
for (int iSummary = 0; iSummary <= 2; iSummary++)
{
Aspose.Tasks.Task Summary = new Aspose.Tasks.Task(SummaryNamesList[iSummary]);
for (int iTask = 0; iTask <= 2; iTask++)
{
Aspose.Tasks.Task task = new Aspose.Tasks.Task(TaskNamesList[iTask]);
if (iTask == 0)
{
task.Start = (new DateTime(2014, 12, 1, 8, 0, 0)).AddDays(6 * iSummary + iTask);
task.ConstraintType = ConstraintType.StartNoEarlierThan;
task.ConstraintDate = task.Start;
}
else
{
//Other tasks start date will be set by adding predecessors
}
task.Duration = new TimeSpan(16 * (1 + iTask), 0, 0);
//Assign resources
ResourceAssignment assgn = new ResourceAssignment(task, prj.Resources[iTask + 1]);
assgn.Start = task.Start;
assgn.Finish = task.Finish;
assgn.Task.Work = assgn.Task.Duration;
assgn.RemainingWork = assgn.Task.Work;
assgn.RegularWork = assgn.RemainingWork;
assgn.Work = assgn.RegularWork;
prj.ResourceAssignments.Add(assgn);

//CurrentTasks.Add(task);
Summary.Children.Add(task);
}

rootTask.Children.Add(Summary);
}

//perform recalculations
Recalculate(prj);

//Add predecessors
prj.AddTaskLink(new TaskLink(prj.GetTaskById(2), prj.GetTaskById(3), TaskLinkType.FinishToStart));

//Add Percentage complete
prj.GetTaskById(2).ActualStart = prj.GetTaskById(2).Start;
prj.GetTaskById(2).ActualFinish = prj.GetTaskById(2).Start.AddDays(2);

prj.AddTaskLink(new TaskLink(prj.GetTaskById(3), prj.GetTaskById(4), TaskLinkType.FinishToStart));

prj.GetTaskById(3).ActualStart = prj.GetTaskById(3).Start;
prj.GetTaskById(3).ActualFinish = prj.GetTaskById(3).Start.AddDays(4);

prj.AddTaskLink(new TaskLink(prj.GetTaskById(6), prj.GetTaskById(7), TaskLinkType.FinishToStart));
prj.AddTaskLink(new TaskLink(prj.GetTaskById(7), prj.GetTaskById(8), TaskLinkType.FinishToStart));
prj.AddTaskLink(new TaskLink(prj.GetTaskById(10), prj.GetTaskById(11), TaskLinkType.FinishToStart));
prj.AddTaskLink(new TaskLink(prj.GetTaskById(11), prj.GetTaskById(12), TaskLinkType.FinishToStart));
Aspose.Tasks.Task.Recalculate(prj.RootTask); //This is new statment
prj.Save(“ResultProject.MPP”, Aspose.Tasks.Saving.SaveFileFormat.MPP);
}

static public Resource GetTestResource(string name)
{
Resource rsc = new Resource(name);
rsc.MaxUnits = 1;
rsc.Type = ResourceType.Work;
return rsc;
}

static void Recalculate(Project project)
{
project.CalcTaskIds();
project.CalcTaskUids();
project.CalcResourceIds();
project.CalcResourceUids();
project.CalcResourceAssignmentIds();
project.CalcResourceAssignmentUids();
project.CalcCalendarUids();
project.UpdateReferences();
}

Could you please follow this sample to modify your code and let us know your feedback?

kashif.iqbalv,,

i m not able to understand ur samples.

is possible send sample export mpp file from datatable with predcessor and indicator column.

my another doubt,how can i retrive inicator value from file and how can i create custom column.

waiting for ur responce.

Hi Sankar,

Thank you for providing feedback.

a.sankar4:
i m not able to understand ur samples.

This code sample provided some basic steps to create MPP from sample data as follows:

  1. First we add resources to the project.
  2. The summary and children tasks are added such that children tasks are added to the parent tasks in proper order.
  3. Summary task start/finish and duration are calculated by the system.
  4. Child tasks' start dates and duration are mentioned while finish dates are calculated by the system.
  5. No resource assignment is done to summary tasks and it is assigned to children tasks only.
  6. Recalculation is done after all the above steps.
  7. After recalculation predecessors are set and any percentage values are set.
  8. Finally we call Task.Recalculate(Project.RootTask) before saving project to MPP.
a.sankar4:
is possible send sample export mpp file from datatable with predcessor and indicator column.

Regarding creating export MPP file from your sample data, I have some observations as follows:

  1. The summary tasks in your sample file "TreeGrid.mpp" have more duration than the children tasks which seems inconsistent.
  2. The baseline start and finish dates are reverse in order i.e. baseline start is later than the baseline finish date.
It is requested that the sample file may be reviewed again and after corrections (if required) modify your code according to above guidelines and let us know your feedback.

I am afraid that I could not understand the requirement to write indicator column in the output file, as in the Export.mpp file we can see the TICK indicator which shows the task is completed. Also indicator column is populated by MSP based upon the data in file. For example if there is some constraint, the calendar like indicator is displayed in the output MPP file. Therefore, the indicator column is already being displayed in the Export.mpp file.

a.sankar4:
my another doubt,how can i retrive inicator value from file and how can i create custom column.

I tried to search the documentation to find information about reading indicator column but could not find it. The indicator column is auto filled by MSP based upon the data and cannot be set manually.

Following is a sample code which can be used to create a custom column.

static public void TestExtendedAttribute()
{
Project prj = new Project(@"D:\Aspose\Blank2010.mpp");
//add extended attribute definition
ExtendedAttributeDefinition ead = new ExtendedAttributeDefinition();
ead.FieldName = "Text1";
ead.Alias = "Description";
ead.FieldId = Convert.ToInt32(ExtendedAttributeTask.Text1).ToString();
prj.ExtendedAttributes = new List();
prj.ExtendedAttributes.Add(ead);
foreach (Aspose.Tasks.Task task in prj.RootTask.Children)
{
ExtendedAttribute ea = new ExtendedAttribute();
ea.FieldId = ead.FieldId;
ea.Value = string.Format("Description of '{0}'.", task.Name);
task.ExtendedAttribute.Add(ea);
}
prj.Save(@"D:\Aspose\project_res.mpp", Aspose.Tasks.Saving.SaveFileFormat.MPP);
}

Please feel free to write us back if you have any other query related to Aspose.Tasks.

Hi Sankar,


Thank you for contacting Aspose support team again.

Please spare me little time as I am working on this issue and will write back here soon.

Hi Sankar,


I have tried to execute this code but found that it contains some repeated code. A data table is also used but no sample data is available for these tables. I would request you to please send us some code which can be compiled and executed to re-produce the scenario of 3 day instead of 1 day duration issue mentioned in your post.

We can add task using Project.AddTask() function where root task is not required for adding the tasks.

Regarding removing first root node when exporting mpp file, could you please explain the requirement as I could not understand it and will try to provide assistance when details are provided?

Hi Sankar,


Thank you for providing sample data. I have tried to use this sample data with the code provided above however I am afraid that I could not relate it to the columns data in the sample code. There is difference in columns present in the sample data and the sample code using this data. Similarly the functions getChildTask() and getParentTask() (taken from your earlier code) use different columns.

Could you please send us the complete project using these fields which can be used to re-produce this scenario here? We can use this sample data in variety of ways to export it to MPP therefore, as per your requirements, exact code is required to observe the issue.

P.S. In case of large text like some code or sample data as sent in your above post, please copy it to some text file and attach it with the post.

Hi

In my earlier post also i was share sample to u.but your asking again and again.

in this attached file when i click export button mpp file exported.

if you dnt know any idea kindly share any other people address.

Your saying using this sample data varity of ways to export mpp file.

kindle share code,using this code itself need to create predecessor as well.

don't hard code any value. get value using "i" parameter or row/column name.

in my scenario hard code value is changed dynamically.

Thanks in advance

-Sankar

Hi Sankar,


With reference to the 3 days issue it seems that you are using duration = 32 and consider it 32 working days where as if we set duration as 1 day, it is actually taken as 24 hours. One working day contains 8 hours, therefore the 1 day duration => 24 Hours and 32 days means 96 days because 32*3=96.

In your code you may please change duration = “32” to duration = “10:16:00:00” where 10 days = 30 days and 16 hours adds 2 more days thus equating to 32 days.

We are sorry for any inconvenience caused to you in this regard.

Hi kashif.iqbal

Thanks for your duration clarification.

Please give me sample code export file without root task.

kindly read the previous post and give me the solution for export MPP file using i m attached sample data.

kindly do the needful.

Thanks

-Sankar

Hi Sankar,


Following is a sample code where your data is used. It should be observed that small changes are made in data like time is added with actual start and finish dates. The duration and percent complete are automatically calculated when project is saved. Please give it a try and let us know your feedback.


static public void ExportProject()
{
DataTable dt = Sample();
List lstTasks = new List();
Project project = new Project(@“D:\Aspose\Blank2010.mpp”);
for (int i = 0; i < dt.Rows.Count; i++)
{
//Set Task name
string taskName = dt.Rows[i][“TaskName”].ToString();
Task tsk = project.AddTask(taskName);

//Set Task Actual start/Finish
DateTime dtStart = Convert.ToDateTime(dt.Rows[i][“taskactualstartdate”].ToString());
DateTime dtFinish = Convert.ToDateTime(dt.Rows[i][“taskactualfinishdate”].ToString());
tsk.ActualStart = dtStart;
tsk.ActualFinish = dtFinish;

//Set Task Baseline start/Finish
DateTime dtBLStart = Convert.ToDateTime(dt.Rows[i][“taskbaselinestartdate”].ToString());
DateTime dtBLFinish = Convert.ToDateTime(dt.Rows[i][“taskbaselinefinishdate”].ToString());
TaskBaseline tskbase = new TaskBaseline();
tskbase.Start = dtBLStart;
tskbase.Finish = dtBLFinish;
tsk.Baseline.Add(tskbase);

lstTasks.Add(tsk);
}
for (int i = 0; i < dt.Rows.Count; i++)
{
string taskOutlineLevel = dt.Rows[i][“taskoutlinelevel”].ToString();
int iOutlineLevel = Convert.ToInt32(taskOutlineLevel);
for (int j = 0; j < iOutlineLevel; j++)
lstTasks[i].OutlineIndent();
}
project.Save(“Output.mpp”, SaveFileFormat.MPP);
}

static public DataTable Sample()
{
DataTable dt = new DataTable();
dt.Columns.Add(“TaskuID”);
dt.Columns.Add(“taskparentuID”);
dt.Columns.Add(“TaskName”);
dt.Columns.Add(“taskbaselinestartdate”);
dt.Columns.Add(“taskbaselinefinishdate”);
dt.Columns.Add(“taskactualstartdate”);
dt.Columns.Add(“taskactualfinishdate”);
dt.Columns.Add(“percentcomplete”);
dt.Columns.Add(“Taskissummary”);
dt.Columns.Add(“taskoutlinenumber”);
dt.Columns.Add(“taskoutlinelevel”);
dt.Columns.Add(“taskindex”);
dt.Columns.Add(“duration”);
dt.Columns.Add(“ResourceName”);
dt.Columns.Add(“ReasonForDelay”);
dt.Columns.Add(“Projectuid”);
dt.Columns.Add(“predecessors”);
dt.Columns.Add(“indicator”);


DataRow dr = dt.NewRow();

dr[“TaskuID”] = “DA0559F7-B255-4E06-87E3-ECC80E76D5CC”;
dr[“taskparentuID”] = “DA0559F7-B355-4E06-87E3-ECC80E76D5CC”;
dr[“TaskName”] = “sankar PPE_DEMO_Transition-PPE_DEMO_process_transition_20121203_145438”;
dr[“taskbaselinestartdate”] = “02-02-2009 08:00:00”;
dr[“taskbaselinefinishdate”] = “03-16-2009 17:00:00”;
dr[“taskactualstartdate”] = “02-02-2009 08:00:00”;
dr[“taskactualfinishdate”] = “03-16-2009 17:00:00”;
dr[“percentcomplete”] = “0”;
dr[“Taskissummary”] = “1”;
dr[“taskoutlinenumber”] = “0”;
dr[“taskoutlinelevel”] = “0”;
dr[“taskindex”] = “1”;
dr[“duration”] = “10:16:00:00”;
dr[“ResourceName”] = “”;
dr[“ReasonForDelay”] = “”;
dr[“Projectuid”] = “628d19fc-c951-4532-8ea7-90f5d35e3442”;
dr[“predecessors”] = “”;
dr[“indicator”] = “”;
dt.Rows.Add(dr);

DataRow dr1 = dt.NewRow();
dr1[“TaskuID”] = “A7CCFD48-B85F-46B2-B270-1B86363C6E22”;
dr1[“taskparentuID”] = “DA0559F7-B255-4E06-87E3-ECC80E76D5CC”;
dr1[“TaskName”] = “sankar Generic Transition Project Plan - Start off point”;
dr1[“taskbaselinestartdate”] = “02-02-2009 08:00:00”;
dr1[“taskbaselinefinishdate”] = “03-02-2009 17:00:00”;
dr1[“taskactualstartdate”] = “02-02-2009 08:00:00”;
dr1[“taskactualfinishdate”] = “03-16-2009 17:00:00”;
dr1[“percentcomplete”] = “0”;
dr1[“Taskissummary”] = “1”;
dr1[“taskoutlinenumber”] = “1”;
dr1[“taskoutlinelevel”] = “1”;
dr1[“taskindex”] = “1”;
dr1[“duration”] = “10:16:00:00”;
dr1[“ResourceName”] = “”;
dr1[“ReasonForDelay”] = “”;
dr1[“Projectuid”] = “628d19fc-c951-4532-8ea7-90f5d35e3442”;
dr1[“predecessors”] = “”;
dr1[“indicator”] = “”;
dt.Rows.Add(dr1);

DataRow dr2 = dt.NewRow();
dr2[“TaskuID”] = “A2CCFD48-B85F-46B2-B270-1B86363C6E22”;
dr2[“taskparentuID”] = “A7CCFD48-B85F-46B2-B270-1B86363C6E22”;
dr2[“TaskName”] = “babu Generic Transition Project Plan - Start off point”;
dr2[“taskbaselinestartdate”] = “02-02-2009 08:00:00”;
dr2[“taskbaselinefinishdate”] = “03-02-2009 17:00:00”;
dr2[“taskactualstartdate”] = “02-02-2009 08:00:00”;
dr2[“taskactualfinishdate”] = “03-16-2009 17:00:00”;
dr2[“percentcomplete”] = “0”;
dr2[“Taskissummary”] = “1”;
dr2[“taskoutlinenumber”] = “1”;
dr2[“taskoutlinelevel”] = “1”;
dr2[“taskindex”] = “0”;
dr2[“duration”] = “10:16:00:00”;
dr2[“ResourceName”] = “”;
dr2[“ReasonForDelay”] = “”;
dr2[“Projectuid”] = “628d19fc-c951-4532-8ea7-90f5d35e3442”;
dr2[“predecessors”] = “”;
dr2[“indicator”] = “”;
dt.Rows.Add(dr2);

return dt;
}

hi ,

its in working fine in minimum record .. in my senario have more than 350 record so its take too much time(wait more than 15 min but file is not exported).

Export project also have parent child relation as well.

so kindly share any other way to export.

Thanks

-Sankar

Hi Sankar,


Its good to know that the errors have been resolved at your end. Please note that I have just rectified some of the data from your sample records that you provided to us. There may have similar errors in your other data as well that you need to check and rectify at your end. I am not sure if these are the real reasons behind the slow speed that you are complaining about. However, you can provide us the complete sample data as above (in rectified form) and we can test that at our end for investigating the issue further and assist you.

PS: We are in process of releasing the revamped version of Aspose.Tasks in a week time that brings much more improvements in performance and functionality.

Dear kashif,

After creating MPP file it is open in 2010 version its showing correct data.

but in 2007 Version start, finish and duration data was mismatched, its taking current date.

please find the attached image.

send contact details to discuss regarding this.

Thanks

Sankar