Hi,
I am trying to create split tasks but my efforts so far have failed. I am using the following code. This is based on code I found on your support forum. Can you please review and show me where I’m going wrong?
An interesting behavior I’ve noted is I can split tasks within the initial mpp template, but once I use this template and save it as a new mpp file, I can no longer split tasks. Maybe this will help you isolate what I’m doing wrong?
Thanks in advance…
Project _project = new Project("c:\\temp\\splitTemplate.mpp");
Aspose.Tasks.Calendar calendar = _project.Get(Prj.Calendar);
_project.Set(Prj.StartDate, new DateTime(2014, 4, 30, 8, 0, 0));
//Add a new task
Aspose.Tasks.Task taskToSplit = _project.RootTask.Children.Add("Activity1");
taskToSplit.Set(Tsk.Start, new DateTime(2014, 4, 30, 8, 0, 0));
taskToSplit.Set(Tsk.Duration, _project.GetDuration(40.00, TimeUnitType.Hour));
DateTime calFinishDateTime = calendar.GetFinishDateByStartAndWork(taskToSplit.Get(Tsk.Start), taskToSplit.Get(Tsk.Duration));
taskToSplit.Set(Tsk.Finish, calFinishDateTime);
taskToSplit.Set(Tsk.DurationFormat, TimeUnitType.Day);
//Create a new resource assignment
ResourceAssignment splitResourceAssignment = _project.ResourceAssignments.Add(taskToSplit, null);
splitResourceAssignment.Set(Asn.Start, taskToSplit.Get(Tsk.Start));
splitResourceAssignment.Set(Asn.Finish, taskToSplit.Get(Tsk.Finish));
//Generate resource assignment timephased data
splitResourceAssignment.TimephasedDataFromTaskDuration(calendar);
//Split the task into 2 parts.
splitResourceAssignment.SplitTask(new DateTime(2014, 5, 1, 8, 0, 0), new DateTime(2014, 5, 1, 17, 0, 0), calendar);
splitResourceAssignment.Set(Asn.WorkContour, WorkContourType.Contoured);
string file = "c:\\temp\\SplitTest.mpp";
MPPSaveOptions options = new MPPSaveOptions();
options.WriteViewData = true;
_project.Save(file, options);