I am creating a project XML file from scratch, and I’m having trouble setting the completion percentage on my tasks. I’m not sure the real differences between “PercentComplete”, “PercentWorkComplete”, and “PhysicalPercentComplete”, but I just want to change whatever one shows up in the “Task Information” popup in Microsoft Project (screenshot included).
Hi Brian,
You need to assign resources to the task to change percent complete as you can see in the following example.
static void Main(string[] args)
{
License license = new License();
license.SetLicense(@"Aspose.Total.Product.Family.lic");
Project project = new Project();
project.StartDate = new DateTime(2010, 12, 15, 8, 0, 0);
project.FinishDate = new DateTime(2011, 12, 31, 17, 0, 0);
project.MinutesPerDay = 8 * 60;
project.MinutesPerWeek = 5 * 8 * 60;
project.DaysPerMonth = 20;
project.DefaultStartTime = new DateTime(1, 1, 1, 8, 0, 0);
project.DefaultFinishTime = new DateTime(1, 1, 2, 17, 0, 0);
project.DurationFormat = TimeUnitType.Hour;
project.WorkFormat = TimeUnitType.Hour;
Calendar standard = new Calendar("Standard");
standard = Calendar.MakeStandardCalendar(standard);
project.Calendars.Add(standard);
project.Calendar = standard;
Calendar employeeCalendar = new Calendar("Employee");
employeeCalendar.BaseCalendar = standard;
project.Calendars.Add(employeeCalendar);
//Create root task.
Task root = new Task();
root.Uid = project.NextTaskUid;
root.Type = TaskType.FixedUnits;
project.RootTask = root;
//Create a new completed task.
Task task = new Task("New task.");
task.Uid = project.NextTaskUid;
task.Type = TaskType.FixedUnits;
task.Start = new DateTime(2010, 12, 15, 8, 0, 0);
task.Duration = new TimeSpan(80, 0, 0);
task.Finish = standard.GetFinishDateByStartAndWork(task.Start, task.Duration);
task.DurationFormat = TimeUnitType.Day;
task.Work = task.Duration;
task.RegularWork = task.Work;
task.ActualStart = task.Start;
task.ActualFinish = task.Finish;
task.ActualDuration = task.Duration;
task.ActualWork = task.Work;
task.PercentComplete = 90;
project.RootTask.Children.Add(task);
//Create a root resource.
Resource res = new Resource();
res.Uid = project.NextResourceUid;
project.Resources.Add(res);
//Create a new resource.
Resource resource = new Resource();
resource.Name = "Employee";
resource.Type = ResourceType.Work;
resource.Work = new TimeSpan(72, 0, 0);
resource.RegularWork = resource.Work;
resource.ActualWork = resource.Work;
resource.Uid = project.NextResourceUid;
resource.Calendar = employeeCalendar;
project.Resources.Add(resource);
//Create a resource assignment.
ResourceAssignment resourceAssignment = new ResourceAssignment();
resourceAssignment.Uid = project.NextResourceAssignmentUid;
resourceAssignment.Task = task;
resourceAssignment.Resource = resource;
resourceAssignment.ActualWork = resource.Work;
resourceAssignment.Work = resource.Work;
resourceAssignment.RegularWork = resource.Work;
resourceAssignment.Start = task.Start;
resourceAssignment.Finish = task.Finish;
resourceAssignment.ActualStart = resourceAssignment.Start;
resourceAssignment.ActualFinish = resourceAssignment.Finish;
resourceAssignment.Units = 1;
project.ResourceAssignments.Add(resourceAssignment);
project.CalcCalendarUids();
project.CalcTaskIds();
project.CalcResourceIds();
project.CalcResourceAssignmentIds();
ProjectWriter writer = new ProjectWriter();
writer.Write(project, "Project1.xml", TasksDataFormat.XML);
}
Please feel free to contact us in case you have further comments or questions.
Best Regards,
Thanks for the response. Why would I need to add a resource in order to change the completion percentage though? If I go straight to project, I can double click on a task, change the percent complete, and it’s done. No need to create/assign resources there.
Hi,
That might be due to some internal dependencies. The concerned team will provide you more details on this shortly.
Many Thanks
Hi Brian,
You can use the following code to change the percentage of a task without a resource or create a new task with percent complete value.
License license = new License();
license.SetLicense(@"Aspose.Total.Product.Family.lic");
Project project = new Project();
project.StartDate = new DateTime(2010, 12, 15, 8, 0, 0);
project.FinishDate = new DateTime(2011, 12, 31, 17, 0, 0);
project.MinutesPerDay = 8 * 60;
project.MinutesPerWeek = 5 * 8 * 60;
project.DaysPerMonth = 20;
project.DefaultStartTime = new DateTime(1, 1, 1, 8, 0, 0);
project.DefaultFinishTime = new DateTime(1, 1, 2, 17, 0, 0);
project.DurationFormat = TimeUnitType.Hour;
project.WorkFormat = TimeUnitType.Hour;
Calendar standard = new Calendar("Standard");
standard = Calendar.MakeStandardCalendar(standard);
project.Calendars.Add(standard);
project.Calendar = standard;
//Create root task.
Task root = new Task();
root.Uid = project.NextTaskUid;
root.Type = TaskType.FixedUnits;
project.RootTask = root;
//Create a new 90% completed task.
Task task = new Task("New task.");
task.Uid = project.NextTaskUid;
task.Type = TaskType.FixedUnits;
task.Start = new DateTime(2010, 12, 15, 8, 0, 0);
task.Duration = new TimeSpan(80, 0, 0);
task.Finish = standard.GetFinishDateByStartAndWork(task.Start, task.Duration);
task.DurationFormat = TimeUnitType.Day;
task.Work = task.Duration;
task.RegularWork = task.Work;
task.ActualStart = task.Start;
task.ActualFinish = task.Finish;
task.ActualDuration = task.Duration;
task.ActualWork = new TimeSpan(72, 0, 0); ;
project.RootTask.Children.Add(task);
project.CalcCalendarUids();
project.CalcTaskIds();
ProjectWriter writer = new ProjectWriter();
writer.Write(project, "Project1.xml", TasksDataFormat.XML);
A new issue to add method to change task progress has also been logged into our issue tracking system as TASKS-22450. We will keep you updated on this issue in this thread.
Please feel free to contact us in case you have further comments or questions.
Best Regards,
The issues you have found earlier (filed as TASKS-22450) have been fixed in this update.
This message was posted using Notification2Forum from Downloads module by aspose.notifier.
The issues you have found earlier (filed as ) have been fixed in this Aspose.Words for JasperReports 18.3 update.