Incorrect Task Data / References in Updated MPP File

Hi,

We added tasks to a blank MPP file by fetching the records from DB and saved the mpp. When I open the updated mpp file and modify any task duration, all the start and end dates become NA. Attached are the two mpp files:

blank.mpp - before updating

TestOutput.mpp - After adding tasks. Change any duration or a date in this file and you will see the dates or duration becoming NA. Below is the code that we are using

public void GetMPPProjectInfo(int assetId, string outputPath)
{
try
{

//create a project instance
License license = new License();
license.SetLicense("Aspose.Total.lic");

ProjectReader pr = new ProjectReader();
Aspose.Tasks.Project prj = pr.Read("C:\\poorna\\Blank.MPP");

Aspose.Tasks.Util.ChildTasksCollector collector1 = new Aspose.Tasks.Util.ChildTasksCollector();
Aspose.Tasks.Util.TaskUtils.Apply(prj.RootTask, collector1, 0);



List lstProjectTasks = GetMPPProjectTasks(assetId);


//project Information

if (prj.RootTask.Calendar == null)
{
prj.RootTask.Calendar = Calendar.Make24HourCalendar();
}

ArrayList projectExtendedAttributes = new ArrayList();

ExtendedAttributeDefinition tastEntityTypeAttr = new ExtendedAttributeDefinition();
tastEntityTypeAttr.Alias = "EntityTypeId";
tastEntityTypeAttr.FieldName = "Number19";
tastEntityTypeAttr.ElementType = ElementType.Task;
tastEntityTypeAttr.CfType = CustomFieldType.Number;

ExtendedAttributeDefinition taskEntityInstanceAttr = new ExtendedAttributeDefinition();
taskEntityInstanceAttr.Alias = "EntityInstanceId";
taskEntityInstanceAttr.FieldName = "Number20";
taskEntityInstanceAttr.ElementType = ElementType.Task;
taskEntityInstanceAttr.CfType = CustomFieldType.Number;


projectExtendedAttributes.Add(tastEntityTypeAttr);
projectExtendedAttributes.Add(taskEntityInstanceAttr);

AddChildrends(prj.RootTask, null, null, 1, assetId, null, null, 22);

//perform recalculations
prj.CalcTaskIds();
prj.CalcTaskUids();
prj.UpdateReferences();
//create a project writer instance
prj.Save(outputPath, Aspose.Tasks.Saving.SaveFileFormat.MPP);


}
catch (Exception ex)
{
throw ex;
}
}


public void AddChildrends(Aspose.Tasks.Task parentTask, int? parentEntityTypeId, int? parentEntityInstanceId, int? entityTypeId, int? entityInstanceId, int? uId, int? id, int? userId)
{
Aspose.Tasks.Task tsk;
int k = 1;
int j = 1;

ArrayList projectExtendedAttributes = new ArrayList();

ExtendedAttributeDefinition taskEntityTypeAttr = new ExtendedAttributeDefinition();
taskEntityTypeAttr.Alias = "EntityTypeId";
taskEntityTypeAttr.FieldName = "Number19";
taskEntityTypeAttr.ElementType = ElementType.Task;
taskEntityTypeAttr.CfType = CustomFieldType.Number;

ExtendedAttributeDefinition taskEntityInstanceAttr = new ExtendedAttributeDefinition();
taskEntityInstanceAttr.Alias = "EntityInstanceId";
taskEntityInstanceAttr.FieldName = "Number20";
taskEntityInstanceAttr.ElementType = ElementType.Task;
taskEntityInstanceAttr.CfType = CustomFieldType.Number;


projectExtendedAttributes.Add(taskEntityTypeAttr);
projectExtendedAttributes.Add(taskEntityInstanceAttr);
ExtendedAttribute taskAttr;


List lstMPPTasks = GetMPPTasksToExport(parentEntityTypeId, parentEntityInstanceId, entityTypeId, entityInstanceId, uId, id, userId);
foreach (ProjectTasksViewModel mv in lstMPPTasks)
{
tsk = new Aspose.Tasks.Task();
//tsk.Uid = k++;
//tsk.Id = j++;
tsk.Name = mv.MPPTaskName;
//tsk.Start = mv.ActualStartDate == null ? DateTime.Now : (DateTime)mv.ActualStartDate;
//tsk.Finish = mv.ActualEndDate == null ? DateTime.Now : (DateTime)mv.ActualEndDate;
//tsk.Duration = TimeSpan.FromDays(mv.Duration == 0 ? 1 : (double)mv.Duration);

tsk.Start = mv.ActualStartDate == null ? DateTime.Now : (DateTime)mv.ActualStartDate;
tsk.Duration = TimeSpan.FromDays(mv.Duration == 0 ? 1 : (double)mv.Duration);
tsk.DurationFormat = TimeUnitType.Day;
tsk.Deadline = tsk.Deadline.AddDays(1 + 1);
tsk.Finish = mv.ActualEndDate == null ? DateTime.Now : (DateTime)mv.ActualEndDate;

tsk.ExtendedAttribute = new ArrayList(1);
taskAttr = new ExtendedAttribute();
taskAttr.AttributeDefinition = taskEntityTypeAttr;
taskAttr.Value = mv.EntityTypeId.ToString();
taskAttr.FieldId = taskEntityTypeAttr.FieldId;
tsk.ExtendedAttribute.Add(taskAttr);


taskAttr = new ExtendedAttribute();
taskAttr.AttributeDefinition = taskEntityInstanceAttr;
taskAttr.Value = mv.EntityInstanceId.ToString();
taskAttr.FieldId = taskEntityInstanceAttr.FieldId;
tsk.ExtendedAttribute.Add(taskAttr);

parentTask.Children.Add(tsk);
AddChildrends(tsk, mv.EntityTypeId, mv.EntityInstanceId, entityTypeId, entityInstanceId, uId, id, userId);

}
}

public void GetMPPProjectInfo(int assetId, string outputPath)
{
try
{

//create a project instance
License license = new License();
license.SetLicense("Aspose.Total.lic");

ProjectReader pr = new ProjectReader();
Aspose.Tasks.Project prj = pr.Read("C:\\poorna\\Blank.MPP");

Aspose.Tasks.Util.ChildTasksCollector collector1 = new Aspose.Tasks.Util.ChildTasksCollector();
Aspose.Tasks.Util.TaskUtils.Apply(prj.RootTask, collector1, 0);



List lstProjectTasks = GetMPPProjectTasks(assetId);


//project Information

if (prj.RootTask.Calendar == null)
{
prj.RootTask.Calendar = Calendar.Make24HourCalendar();
}

ArrayList projectExtendedAttributes = new ArrayList();

ExtendedAttributeDefinition tastEntityTypeAttr = new ExtendedAttributeDefinition();
tastEntityTypeAttr.Alias = "EntityTypeId";
tastEntityTypeAttr.FieldName = "Number19";
tastEntityTypeAttr.ElementType = ElementType.Task;
tastEntityTypeAttr.CfType = CustomFieldType.Number;

ExtendedAttributeDefinition taskEntityInstanceAttr = new ExtendedAttributeDefinition();
taskEntityInstanceAttr.Alias = "EntityInstanceId";
taskEntityInstanceAttr.FieldName = "Number20";
taskEntityInstanceAttr.ElementType = ElementType.Task;
taskEntityInstanceAttr.CfType = CustomFieldType.Number;


projectExtendedAttributes.Add(tastEntityTypeAttr);
projectExtendedAttributes.Add(taskEntityInstanceAttr);

AddChildrends(prj.RootTask, null, null, 1, assetId, null, null, 22);

//perform recalculations
prj.CalcTaskIds();
prj.CalcTaskUids();
prj.UpdateReferences();
//create a project writer instance
prj.Save(outputPath, Aspose.Tasks.Saving.SaveFileFormat.MPP);


}
catch (Exception ex)
{
throw ex;
}
}


public void AddChildrends(Aspose.Tasks.Task parentTask, int? parentEntityTypeId, int? parentEntityInstanceId, int? entityTypeId, int? entityInstanceId, int? uId, int? id, int? userId)
{
Aspose.Tasks.Task tsk;
int k = 1;
int j = 1;

ArrayList projectExtendedAttributes = new ArrayList();

ExtendedAttributeDefinition taskEntityTypeAttr = new ExtendedAttributeDefinition();
taskEntityTypeAttr.Alias = "EntityTypeId";
taskEntityTypeAttr.FieldName = "Number19";
taskEntityTypeAttr.ElementType = ElementType.Task;
taskEntityTypeAttr.CfType = CustomFieldType.Number;

ExtendedAttributeDefinition taskEntityInstanceAttr = new ExtendedAttributeDefinition();
taskEntityInstanceAttr.Alias = "EntityInstanceId";
taskEntityInstanceAttr.FieldName = "Number20";
taskEntityInstanceAttr.ElementType = ElementType.Task;
taskEntityInstanceAttr.CfType = CustomFieldType.Number;


projectExtendedAttributes.Add(taskEntityTypeAttr);
projectExtendedAttributes.Add(taskEntityInstanceAttr);
ExtendedAttribute taskAttr;


List lstMPPTasks = GetMPPTasksToExport(parentEntityTypeId, parentEntityInstanceId, entityTypeId, entityInstanceId, uId, id, userId);
foreach (ProjectTasksViewModel mv in lstMPPTasks)
{
tsk = new Aspose.Tasks.Task();
//tsk.Uid = k++;
//tsk.Id = j++;
tsk.Name = mv.MPPTaskName;
//tsk.Start = mv.ActualStartDate == null ? DateTime.Now : (DateTime)mv.ActualStartDate;
//tsk.Finish = mv.ActualEndDate == null ? DateTime.Now : (DateTime)mv.ActualEndDate;
//tsk.Duration = TimeSpan.FromDays(mv.Duration == 0 ? 1 : (double)mv.Duration);

tsk.Start = mv.ActualStartDate == null ? DateTime.Now : (DateTime)mv.ActualStartDate;
tsk.Duration = TimeSpan.FromDays(mv.Duration == 0 ? 1 : (double)mv.Duration);
tsk.DurationFormat = TimeUnitType.Day;
tsk.Deadline = tsk.Deadline.AddDays(1 + 1);
tsk.Finish = mv.ActualEndDate == null ? DateTime.Now : (DateTime)mv.ActualEndDate;

tsk.ExtendedAttribute = new ArrayList(1);
taskAttr = new ExtendedAttribute();
taskAttr.AttributeDefinition = taskEntityTypeAttr;
taskAttr.Value = mv.EntityTypeId.ToString();
taskAttr.FieldId = taskEntityTypeAttr.FieldId;
tsk.ExtendedAttribute.Add(taskAttr);


taskAttr = new ExtendedAttribute();
taskAttr.AttributeDefinition = taskEntityInstanceAttr;
taskAttr.Value = mv.EntityInstanceId.ToString();
taskAttr.FieldId = taskEntityInstanceAttr.FieldId;
tsk.ExtendedAttribute.Add(taskAttr);

parentTask.Children.Add(tsk);
AddChildrends(tsk, mv.EntityTypeId, mv.EntityInstanceId, entityTypeId, entityInstanceId, uId, id, userId);

}
}

Hi Subramanyam,


We are sorry for any inconvenience caused to you.

I would request you to please check this issue with the latest version of Aspose.Tasksfor .NET 5.2.0 as well as 5.1.0, and let us know if the behaviour is the same with 5.1.0 version as well. The reason for checking with one version old is that we have hit regression issue with the latest version 5.2.0 that directly affects MPP 2010 functionality, and we are in process of fixing that.

In case, the issue is reproducible with version 5.1.0 as well, I would request you to please provide us some sample runnable console application that we can use to reproduce this issue at our end for reporting to our development team. We’ll look into it for investigation and assist you further.




Hi Kashif,

The problem was resolved with version 5.1.0.

Thanks

Subbu

Actually, the issue still exists. The blank file was from MSP 2007 and the newly created file is also created in MSP 2007 as it is from that blank file. When we open the newly created file and edit it in 2007 version, it works fine. But when we use MSP 2010 version to edit it, it has the same issue where the dates are getting vanished. Any suggestions?

Hi Subramanyam,


I have tried to reproduce the scenario by using your above mentioned sample code but could not succeed as code cannot be compiled due to missing references.

I have analyzed the “TestOutPut.MPP” file sent in your first post and can observe the issue in MSP 2010 and MSP 2013 both. However I also observed that if we press “Calculate Project” on Project tab, everything goes fine and issue is removed. For further investigation it is must required that we re-produce the issue here.

Could you please modify above sample code such that you hard code one or two tasks instead of reading all from Database. As soon as we get the working console application, we will be in better position to assist you in this regard.

Thanks in advance for your cooperation and understanding in this regard.

I have modified the code without any reference.

While executing the below code, i have accessing 2007 blank.mpp file.

CODE:

License license = new License();
license.SetLicense("Aspose.Total.lic");

ProjectReader pr = new ProjectReader();
Aspose.Tasks.Project prj = pr.Read("c:\\files\\blank.mpp");

Aspose.Tasks.Util.ChildTasksCollector collector1 = new Aspose.Tasks.Util.ChildTasksCollector();
Aspose.Tasks.Util.TaskUtils.Apply(prj.RootTask, collector1, 0);


if (prj.RootTask.Calendar == null)
{
prj.RootTask.Calendar = Calendar.MakeStandardCalendar();
}


ArrayList projectExtendedAttributes = new ArrayList();

ExtendedAttributeDefinition tastEntityTypeAttr = new ExtendedAttributeDefinition();
tastEntityTypeAttr.Alias = "EntityTypeId";
tastEntityTypeAttr.FieldName = "Number19";
tastEntityTypeAttr.ElementType = ElementType.Task;
tastEntityTypeAttr.CfType = CustomFieldType.Number;

ExtendedAttributeDefinition taskEntityInstanceAttr = new ExtendedAttributeDefinition();
taskEntityInstanceAttr.Alias = "EntityInstanceId";
taskEntityInstanceAttr.FieldName = "Number20";
taskEntityInstanceAttr.ElementType = ElementType.Task;
taskEntityInstanceAttr.CfType = CustomFieldType.Number;

ExtendedAttribute taskAttr;

projectExtendedAttributes.Add(tastEntityTypeAttr);
projectExtendedAttributes.Add(taskEntityInstanceAttr);

Aspose.Tasks.Task tsk1 = new Aspose.Tasks.Task();
tsk1 = new Aspose.Tasks.Task();
tsk1.DurationFormat = TimeUnitType.Day;
tsk1.Name = "Task1";
tsk1.Start = DateTime.Now;
tsk1.Duration = TimeSpan.FromHours(24);
tsk1.Finish = DateTime.Now.AddDays(3);

tsk1.ExtendedAttribute = new ArrayList(1);
taskAttr = new ExtendedAttribute();
taskAttr.AttributeDefinition = tastEntityTypeAttr;
taskAttr.Value = "15";
taskAttr.FieldId = tastEntityTypeAttr.FieldId;
tsk1.ExtendedAttribute.Add(taskAttr);


taskAttr = new ExtendedAttribute();
taskAttr.AttributeDefinition = taskEntityInstanceAttr;
taskAttr.Value = "1";
taskAttr.FieldId = taskEntityInstanceAttr.FieldId;
tsk1.ExtendedAttribute.Add(taskAttr);

prj.RootTask.Children.Add(tsk1);


prj.CalcCalendarUids();
prj.CalcTaskIds();
prj.CalcTaskUids();
prj.UpdateReferences();
prj.Save("c:\\files\\output.mpp", Aspose.Tasks.Saving.SaveFileFormat.MPP);

Hi Subramanyam,


I have tested the code but getting exception while writing to output.mpp at the end. Could you please verify if you are getting some exception while using Aspose.Tasks for .NET 5.2.0 with the above mentioned code?





unfortuanately yes and we are unable to figure out why the issue is happening?

Hi Subramanyam,


It seems to be some regression issue and I am in contact with the development team for a resolution. I will inform you via this thread as soon as some feedback is received from the developers.

Please spare us little time and be patient for a while.

I think it’s the same issue when we use 5.1.0 also.

Hi Subramanyam,


I have tested this issue with Aspose.Tasks for .NET 5.1.0, and was unable to observe the issue when the result file is opened in MSP 2010. My steps:

  1. Used the Aspose.Tasks 5.1.0
  2. Used Blank.mpp provided in your very first thread as an input
  3. Executed the runnable code
  4. Opened the output MPP file in MSP 2010
  5. Changed duration from 3 to X days
The resultant file didn’t cause the dates to change to NA when I make changes. I have attached the output MPP file here for your reference. Please open it at your end in MSP 2010 and let us know your feedback.

I dont see the attachment from you. can you send it?

Hi Subramanyam,


Sorry for the inconvenience caused. I have attached here now for your reference.

The issue exists in this file also. since it is only one task you are not able to see it. If you click on “calculate Project” under project tab in MSP 2010 for file, you will see that the dates get changed for the one task that you have in the file. The problem I think is that recalculation of the project data is not happening. Once I click on re-calculate, then I am able to change all dates. Till that recalculation happens, the issue with date change exists :frowning:

Hi Subramanyam,


Can you confirm to us if the same project, when opened in MSP 2007, works fine for you? Due to the absense of MSP 2007 at my end, I am unable to test it and would request your feedback here.

We are investigating this issue, and will soon provide our feedback in this case.

Hi Subramanyam,


After detailed analysis of the code we found that dates problem can be resolved by setting the “Project start date” to first task start date as given below:

prj.StartDate = tsk1.Start;

Similarly its found that ExtendedAttributeDefinition.FieldId must always be set as it was causing the exception. Following statements need to be added.
tastEntityTypeAttr.FieldId = ((int)ExtendedAttributeTask.Number19).ToString();
taskEntityInstanceAttr.FieldId = ((int)ExtendedAttributeTask.Number20).ToString();
Could you please give a try to the following code using latest assembly Aspose.Tasks for .NET 5.2.0 and let us know your feedback.

ProjectReader pr = new ProjectReader();
Aspose.Tasks.Project prj = pr.Read("Blank.mpp");
Aspose.Tasks.Util.ChildTasksCollector collector1 = new Aspose.Tasks.Util.ChildTasksCollector();
Aspose.Tasks.Util.TaskUtils.Apply(prj.RootTask, collector1, 0);
if (prj.RootTask.Calendar == null)
{
prj.RootTask.Calendar = Aspose.Tasks.Calendar.MakeStandardCalendar();
}
ArrayList projectExtendedAttributes = new ArrayList();

ExtendedAttributeDefinition tastEntityTypeAttr = new ExtendedAttributeDefinition();
tastEntityTypeAttr.Alias = "EntityTypeId";
tastEntityTypeAttr.FieldName = "Number19";
//This line is added
tastEntityTypeAttr.FieldId = ((int)ExtendedAttributeTask.Number19).ToString();
tastEntityTypeAttr.ElementType = ElementType.Task;
tastEntityTypeAttr.CfType = CustomFieldType.Number;

ExtendedAttributeDefinition taskEntityInstanceAttr = new ExtendedAttributeDefinition();
taskEntityInstanceAttr.Alias = "EntityInstanceId";
taskEntityInstanceAttr.FieldName = "Number20";

//This line is added
taskEntityInstanceAttr.FieldId = ((int)ExtendedAttributeTask.Number20).ToString();
taskEntityInstanceAttr.ElementType = ElementType.Task;
taskEntityInstanceAttr.CfType = CustomFieldType.Number;

ExtendedAttribute taskAttr;
projectExtendedAttributes.Add(tastEntityTypeAttr);
projectExtendedAttributes.Add(taskEntityInstanceAttr);

Aspose.Tasks.Task tsk1 = new Aspose.Tasks.Task();
tsk1 = new Aspose.Tasks.Task();
tsk1.DurationFormat = TimeUnitType.Day;
tsk1.Name = "Task1";
tsk1.Start = DateTime.Now;
tsk1.Duration = TimeSpan.FromHours(24);
tsk1.Finish = DateTime.Now.AddDays(3);

tsk1.ExtendedAttribute = new ArrayList(1);

taskAttr = new ExtendedAttribute();
taskAttr.AttributeDefinition = tastEntityTypeAttr;
taskAttr.Value = "15";
taskAttr.FieldId = tastEntityTypeAttr.FieldId;
tsk1.ExtendedAttribute.Add(taskAttr);

taskAttr = new ExtendedAttribute();
taskAttr.AttributeDefinition = taskEntityInstanceAttr;
taskAttr.Value = "1";
taskAttr.FieldId = taskEntityInstanceAttr.FieldId;
tsk1.ExtendedAttribute.Add(taskAttr);
prj.RootTask.Children.Add(tsk1);
prj.CalcCalendarUids();
prj.CalcTaskIds();
prj.CalcTaskUids();
prj.UpdateReferences();

//This line is added
prj.StartDate = tsk1.Start;
prj.Save("output.mpp", Aspose.Tasks.Saving.SaveFileFormat.MPP);

Hi Subramanyam,


I have tried the scenario where updated file is modified using MSP-2010 and dates become NA. These details are provided to developers and they will soon analyze it and share their findings. I have logged this issue under id: TASKS-33313 in our issue tracking system.

The issue of difference in task dates for resultant MPP file using MSP-2007 and MSP-2010 is also observed and logged under id: TASKS-33312.

You will be automatically notified as soon as some feedback or resolution is provided by developers.

Thanks for your patience and understanding in this regard.

Hi Subramanyam,


We have thoroughly investigated the issue related to different dates display after updating the MSP 2007 file. It does not seem to be a bug, but an issue related to dates and recalculations performed by MSP.

Normally we set dates like “task.Start = DateTime.Now”, but its not an appropriate method while working with MSP. For modeling the MSP following should be the way for setting Start date of a task:

task.Start = prj.Calendar.GetNextWorkingDayStart(DateTime.Now);

OR

task.Start = prj.Calendar.GetNextWorkingDayStart(DateTime.Now.AddDays(-1));

OR
DateTime start = prj.DefaultStartTime;
task.Start = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, start.Hour, start.Minute, start.Second);

Please give a try to the following code and let us know your feedback:
ProjectReader pr = new ProjectReader();
Project prj = pr.Read("Blank.mpp");
Util.ChildTasksCollector collector1 = new Util.ChildTasksCollector();
Util.TaskUtils.Apply(prj.RootTask, collector1, 0);

if (prj.RootTask.Calendar == null)
{
prj.RootTask.Calendar = Calendar.MakeStandardCalendar();
}
ArrayList projectExtendedAttributes = new ArrayList();
ExtendedAttributeDefinition tastEntityTypeAttr = new ExtendedAttributeDefinition();
tastEntityTypeAttr.Alias = "EntityTypeId";
tastEntityTypeAttr.FieldName = "Number19";
tastEntityTypeAttr.FieldId = ((int)ExtendedAttributeTask.Number19).ToString();
tastEntityTypeAttr.ElementType = ElementType.Task;
tastEntityTypeAttr.CfType = CustomFieldType.Number;

ExtendedAttributeDefinition taskEntityInstanceAttr = new ExtendedAttributeDefinition();
taskEntityInstanceAttr.Alias = "EntityInstanceId";
taskEntityInstanceAttr.FieldName = "Number20";
taskEntityInstanceAttr.FieldId = ((int)ExtendedAttributeTask.Number20).ToString();
taskEntityInstanceAttr.ElementType = ElementType.Task;
taskEntityInstanceAttr.CfType = CustomFieldType.Number;

ExtendedAttribute taskAttr;
projectExtendedAttributes.Add(tastEntityTypeAttr);
projectExtendedAttributes.Add(taskEntityInstanceAttr);
Task tsk1 = new Task();
tsk1 = new Task();
tsk1.DurationFormat = TimeUnitType.Day;
tsk1.Name = "Task1";
tsk1.Start = prj.Calendar.GetNextWorkingDayStart(DateTime.Now);
tsk1.Duration = TimeSpan.FromHours(24);
tsk1.Finish = prj.Calendar.GetFinishDateByStartAndWork(tsk1.Start, tsk1.Duration);
tsk1.ExtendedAttribute = new ArrayList(1);
taskAttr = new ExtendedAttribute();
taskAttr.AttributeDefinition = tastEntityTypeAttr;
taskAttr.Value = "15";
taskAttr.FieldId = tastEntityTypeAttr.FieldId;
tsk1.ExtendedAttribute.Add(taskAttr);

taskAttr = new ExtendedAttribute();
taskAttr.AttributeDefinition = taskEntityInstanceAttr;
taskAttr.Value = "1";
taskAttr.FieldId = taskEntityInstanceAttr.FieldId;
tsk1.ExtendedAttribute.Add(taskAttr);
prj.RootTask.Children.Add(tsk1);

Task tsk2 = new Task();
tsk2 = new Task();
tsk2.DurationFormat = TimeUnitType.Day;
tsk2.Name = "Task2";
tsk2.Start = prj.Calendar.GetNextWorkingDayStart(DateTime.Now + TimeSpan.FromDays(3));
tsk2.Duration = TimeSpan.FromHours(24);
tsk2.Finish = prj.Calendar.GetFinishDateByStartAndWork(tsk2.Start, tsk2.Duration);
tsk2.ExtendedAttribute = new ArrayList(1);
taskAttr = new ExtendedAttribute();
taskAttr.AttributeDefinition = tastEntityTypeAttr;
taskAttr.Value = "16";
taskAttr.FieldId = tastEntityTypeAttr.FieldId;
tsk2.ExtendedAttribute.Add(taskAttr);
taskAttr = new ExtendedAttribute();
taskAttr.AttributeDefinition = taskEntityInstanceAttr;
taskAttr.Value = "2";
taskAttr.FieldId = taskEntityInstanceAttr.FieldId;
tsk2.ExtendedAttribute.Add(taskAttr);
prj.RootTask.Children.Add(tsk2);
prj.CalcCalendarUids();
prj.CalcTaskIds();
prj.CalcTaskUids();
prj.UpdateReferences();
prj.StartDate = tsk1.Start;
prj.CalculateCriticalPath();

prj.Save("output.mpp", SaveFileFormat.MPP);

I would also like to share that "output.mpp" file can be viewed in MSP2007 and MSP2010 in two modes.

1. MSP2007 Calculation mode is MANUAL and MSP2010 has Calculate Project After Each Edit = ON
This will result the similar Gantt chart view of the "Output.mpp" file in MSP2007 and MSP2010. You may get different result if MSP2007 has Calculation Mode AUTOMATIC, as MSP will recalculate the project as soon as MPP is loaded.

2. If similar result is required after calculation, then you may please add following two lines of code while setting tsk2 properties. Also in this case, MSP2007 may have Calculation Mode as AUTOMATIC.
tsk2.ConstraintDate = tsk2.Start;
tsk2.ConstraintType = ConstraintType.StartNoEarlierThan;
Please feel free to write us back if you have any other query in this regard.

Hi kashif,

I don't want to set the constraint type because then it will cause a problem if I am setting a task link. That constraint type is ok if I don't expect to have any dependency and I want that task to start at a date which is later than the project start date.

How can I ensure that MSP 2010 re-calculates the project as soon as it opens? Is there a way to force that? The reason I ask that is because this is causing problem when I am adding a child task. The duration for the parent task is not getting calculated as soon as the child's duration changes. Either we manually click on Update Project after opening the MSP or set the duration of the parent task in the code based on the all child's duration. That is a big problem if we have to do it everytime.

Any help in this regard will be greatly appreciated.

Thanks

Subbu

Hi Subramanyam,

I have analyzed the requirement and want to share that if we use blank file created from MSP2010, it resolves the problem as no project recaculate is required when output.mpp is opened in MSP2010.

On the Other hand if same blank file (created from MSP 2007) is used, you may try to save the output file in XML format. It also does not require project recalcualte when output file is opened in MSP2010.

Please give try to the above mentioned options and let us know your feedback.