I'm setting the task with start, finish, duration and a constraint of startnoearlierthan along with a constraint date of the start. I'm also setting a resource and resource assignment to this task. In project 2010, it works great. It shows the correct start and end date along with duration. In 2007, however, it shows 0. I then read a post saying that I need to set remainingwork in the resourceassignment. So I set it to the duration of the task. The duration is greatly increased.
All I need it to do is to work in 2007 with the start, end date an duration I set in the task. I would love to just use that. If I have to set the resource assignmetn remainingwork, how can I make it equal to the duration I set in the task.
I tried putting the flag, ignoreresourcecalendar, but it didn't work.
Your post was somehow missed and we are extremely sorry for the delay.
You can use the following code to add a new task with correct start and finish dates and duration. This code will work for both 2007 and 2010 versions of MS Project.
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, "project.xml", TasksDataFormat.XML);
Please feel free to contact us in case you have further comments or questions.