Hi Team,
I’m trying to add a new task into the project and then save the project as xml file. But when i open the project file using MS Project, then i can’t able to see the tasks that i have added. I have the code that i’m using to add the task. Let me know whether i’m doing wrong?
//create a prject instance
Project prj = new Project();
//create a project writer instance
ProjectWriter prjWriter = new ProjectWriter();
Task task1 = new Task(“Main task”);
task1.Start = DateTime.Parse(“10-Aug-2011 9:00 AM”);
task1.Finish = DateTime.Parse(“15-Aug-2011 2:00 PM”);
task1.Children.Add(new Task(“sub task1”));
task1.Children.Add(new Task(“sub task2”));
prj.RootTask.Children.Add(task1);
//create a file stream
FileStream st = new FileStream(@“Tasks.xml”, FileMode.Create, FileAccess.Write);
//write the stream into XML format
prjWriter.Write(prj, st, TasksDataFormat.XML);
st.Close();
-Vijay