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

Free Support Forum - aspose.com

Error in case of adding task in ms project with xml

Hello,
From this forum I found a code for adding task which written by aspose support developer .Code is bellow -

Project project = new Project();

project.MinutesPerDay = 60 * 8;



//Add root task

Task root = new Task();

project.RootTask = root;



//Add child task

Task task = new Task(“Task1”);

task.ActualStart = DateTime.Parse(“10-Aug-2011 9:00 AM”);



//set duration in hours

task.Duration = new TimeSpan(24, 0, 0);

task.DurationFormat = TimeUnitType.Day;



root.Children.Add(task);



//We need to recalculate the IDs only as UIDs were set correctly.

project.CalcTaskIds();

project.CalcTaskUids();



ProjectWriter writer = new ProjectWriter();

writer.Write(project, “c://project.xml”, TasksDataFormat.XML);

@ this code have some error. when import project.xml at ms project then i see starting date are showing error here is “10-Aug-2011 9:00 AM” but at project start date is 8/10/00 .

@ in case of duration here is task.Duration = new TimeSpan(24, 0, 0); but at project is 3 days

@ in case of finish date it should be “12-Aug-2011 9:00 AM” but in project have 15/10/00

So,I have track 3 error issue in this code.Can you tell me what is correct format and easy format.In my project I am fetching all data from DB so need a simple code which is adding a task as per DB.Please give me solution as soon as possible.Its urgent.

Hi,

You can see incorrect year because you are using Aspose.Tasks for .NET in evaluation mode. You will see the correct dates after applying the license. Please check this link http://www.aspose.com/documentation/.net-components/aspose.tasks-for-.net/evaluation-version-limitations.html for more details.

In this example, we are setting 1 day equal to 8 hours and task duration equal to 24 hours which means that task duration is equal to 3 working days (Saturday and Sunday will not be calculated). In MS Project, you can see duration in days because of the following line.

task.DurationFormat = TimeUnitType.Day;

Please feel free to contact us in case you have further comments or questions.

Best Regards,