Hello,
I'm new to aspose tasks, and am having great difficulty with creating a mpp file. I have a pretty big pharma client that wishes to use my product to perform calculations and export it into project, so if this can't work, I would imagine I would have to determine that Aspose Tasks can't handle it.
I have an mpp template that I'm reading from and opening. This template is blank and has no tasks. I would like to add tasks, resources and resource assignments to it on the fly and spit out in the response of my asp.net mvc application. When I save the data using teh following line...
prjWriter.Write(prj, , TasksDataFormat.MPP);
It shows nothing, but when I save it with this. It also doesn't throw any errors...
prjWriter.Write(prj, strm, TasksDataFormat.XML);
It does save it correctly, and I can open it up in project.
Here are code snippets...
Opening up the template....
ProjectReader rdr = new ProjectReader();
FileStream fs = new FileStream(strFromPath, FileMode.Open);
Aspose.Tasks.Project prj = rdr.Read(fs);
fs.Close();
prj.AreNewTasksEffortDriven = false;
prj.DurationFormat = TimeUnitType.Day;
Writing a task (a grandparent,parent and 5 children tasks)...
This is one of the children tasks..
Task pcpaTask = new Task("PC to PA");
pcpaTask.Id = intTaskID;
pcpaTask.Uid = intTaskID;
pcpaTask.OutlineLevel = 3;
if (c.PC > DateTime.Now)
{
pcpaTask.ManualStart = c.PC;
pcpaTask.ManualFinish = c.PA.AddDays(-1);
}
else
{
pcpaTask.ManualStart = c.PC;
pcpaTask.ManualFinish = c.PA.AddDays(-1);
}
pcpaTask.IsEffortDriven = false;
pcpaTask.IsManual = true;
pcpaTask.DurationFormat = TimeUnitType.Day;
pcpaTask.EarlyStart = c.PC;
pcpaTask.EarlyFinish = c.PA.AddDays(-1);
TimeSpan pcpaDays = c.PA.Subtract(c.PC);
pcpaTask.ConstraintType = ConstraintType.StartNoEarlierThan;
pcpaTask.ConstraintDate = c.PC;
pcpaTask.Calendar = Calendar.MakeStandardCalendar();
pcpaTask.ManualDuration = new TimeSpan(pcpaDays.Days, 0, 0, 0);
pcpaTask.Type = TaskType.FixedUnits;
studyTask.Children.Add(pcpaTask);
intTaskID++;
Resource Class...
Resource resource = new Resource(c.CalcType);
resource.Type = ResourceType.Work;
resource.Id = prj.Resources.Count + 1;
resource.Uid = prj.Resources.Count + 1;
//resource.Work = studyTaskForResource.ManualDuration;
prj.Resources.Add(resource);
Resource Assignment Class...
ResourceAssignment pcpaResAssign = new ResourceAssignment(pcpaTaskForResource, resource);
pcpaResAssign.Units = Decimal.ToDouble(c.PCPA_FULLFTE);
pcpaResAssign.Start = pcpaTaskForResource.ManualStart;
pcpaResAssign.Finish = pcpaTaskForResource.ManualFinish;
pcpaResAssign.Milestone = false;
pcpaResAssign.TimephasedDataFromTaskDuration(pcpaTaskForResource.Calendar);
Save...
prj.CalcResourceIds();
prj.CalcResourceUids();
prj.CalcResourceFields();
prj.CalcTaskIds();
prj.CalcTaskUids();
prj.CalcResourceAssignmentIds();
prj.CalcResourceAssignmentUids();
prj.CalcCalendarUids();
ProjectWriter prjWriter = new ProjectWriter();
HttpContext.Current.Response.ContentType = "application/vnd.ms-project";
HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment; filename=project.mpp");
HttpContext.Current.Response.Flush();
System.IO.Stream strm = HttpContext.Current.Response.OutputStream;
prjWriter.Write(prj, strm, TasksDataFormat.MPP);
HttpContext.Current.Response.End();
(I've also tried saving it directly to the path of the template, but that didn't work either, and it also doens't throw any exceptions)