I am using following code to create the .mpp file programmatically. This create a MS project file with default fields (Task Mode, Task Name, Duration...). I want to add a custom column/fields with name "MYCustom Field" in this new created file. Can any body guide me how to accomplish this.
Microsoft.Office.Interop.MSProject.Application projectApplication = new Microsoft.Office.Interop.MSProject.Application();
projectApplication.Visible = false;
Microsoft.Office.Interop.MSProject.Project ProjectSheet projectApplication.Projects.Add(missing, missing, missing);
projectApplication.ActiveProject.SaveAs("test.mpp", Microsoft.Office.Interop.MSProject.PjFileFormat.pjMPP, missing, missing);
If you work with mpp files only then "Add a custom field" means pick one of standard custom fields: Text1-32, Duration1-.., Date1-.., Number1-.., Flag1-.. depending on what type of your data and assign your own label to the field.
To do that you should use Table.TableField.Add
method. Here is a link to MSDN. Table is a grid on the left in the MS Project.
You can either redefine one of standard tables Available through Application.Tables
or create your own using Application.TableCopy
Application.TableApply
.
From my experience common rule about MS Project Programming: try to find dedicated object for what you need and if there is no such object - check Application.