Certain Version of Project Required?

I have created as simple of a project as I can, yet the output seems to be useless. Here is the code I’m using:


            License license = new License();
license.SetLicense(@“C:\Aspose.Total.lic”);

Project project = new Project();

Task task = new Task(“Added”);

task.Start = new DateTime(2009, 8, 1);
task.Finish = new DateTime(2009, 8, 5);

project.RootTask.Children.Add(task);

ProjectWriter writer = new ProjectWriter();

string path = @“C:\test.xml”;

using (FileStream fs = new FileStream(path, FileMode.Create, FileAccess.Write))
{
writer.Write(project, fs, TasksDataFormat.XML);
}
Seems simple enough, right? I’ve attached the resulting xml file. When I try to open it, it lets me select if I want to import “As a new project”, “Append the data to the active project”, and “Merge the data into the active project”. When I select the first, it just opens what seems to be a completely empty project. When I open up a new project, then select the second option, I get two milestone tasks that start on today’s date (the first one has no name, the second one has the “Added” name, and the duration is displayed in minutes). When I select the third option, I get the same result as the first. Am I doing something wrong here? Do I need a specific version of Project to view xml formatted projects? Here is my version: Microsoft Office Project 2007 (12.0.6423.1000) SP2 MSO (12.0.6554.5001). Thanks for any help you can provide.

Dear Brian,

You need to add the root task before adding other tasks if you are creating the project from scratch. You also need to calculate the IDs as you can see in the following example.

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 = new DateTime(2009, 8, 1);
//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.
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.

Best Regards,

Thank you, that was very helpful.