How to read data from Project and write them back? RRS feed

  • Question

  • Hi, everyone.

    I know how to read data from Project. But I need help to write them back to Project.

    Here is my code about reading data form Project

    public bool LoadData(ref List<TaskRecord> recordList, string _MSPFileName) { bool result = false; _prjApp = new ApplicationClass(); _prjApp.FileOpen(_MSPFileName, true, missing, missing, missing, missing, missing, missing, missing, missing, missing, PjPoolOpen.pjPoolReadOnly, missing, missing, missing, missing); var enumer = _prjApp.Projects.GetEnumerator(); enumer.MoveNext(); var prj = enumer.Current as Project; var taskEumer = prj.Tasks.GetEnumerator(); while (taskEumer.MoveNext()) { var mspTask = taskEumer.Current as Task; if (null == mspTask) { continue; } // TaskRecord class is my class to record the data form Project TaskRecord record = new TaskRecord(); //begin to get the data, some other properties are not listd here. record.Guid = mspTask.Guid; record.ID = mspTask.UniqueID; record.OrderNumber = mspTask.ID; record.TaskName = mspTask.Name; record.OutlineNumber = mspTask.OutlineNumber; recordList.Add(record); } _prjApp.FileClose(PjSaveType.pjDoNotSave, false); _prjApp.Quit(PjSaveType.pjDoNotSave); return result; }

    TaskRecord is a very simple class

    public class TaskRecord
            public string Guid { get; set; }
            public int ID { get; set; }
            public int OrderNumber { get; set; }
            public string TaskName { get; set; }
            public string OutlineNumber { get; set; }

    I would like to wirte a SaceData() method to write the data back. At leat, I would like to write Guid, UniqueId, Name, OutlineNumber back to project. I would like someone help me to modify my current code. Thanks a lot.

    • Edited by waterharbin Wednesday, July 15, 2015 8:41 AM
    Wednesday, July 15, 2015 8:29 AM

All replies