Hi,
I was try to convert xml to mpp, it works. But it always show only few columns once open mpp, and I wanne show other columns , how should i do??
btw, I was used property ‘AppendNewValues’ , but it doesnt work.
this is my code:
Project project = new Project(@"C:\Code\Data\Test-F.xml");
var attr = ExtendedAttributeDefinition.CreateTaskDefinition(CustomFieldType.Text, ExtendedAttributeTask.Text1, "Custom Field");
attr.AppendNewValues = true;
project.ExtendedAttributes.Add(attr);
var task = project.RootTask.Children.Add("Task");
var attribute = attr.CreateExtendedAttribute("ContextContextContext");
foreach (var item in project.RootTask.Children)
{
item.ExtendedAttributes.Add(attribute);
}
project.Save($@"C:\Code\Data\Text-F{DateTime.Now.ToString("yyyyMMddHHmmss")}.mpp", SaveFileFormat.Mpp);
@Jiangqiming,
since you`re opening file from XML view info (View, Table, Filters, etc) is missing in the project.
You can use the following trick to add the column:
Project project = new Project("input.xml");
project.Save("output.mpp"); // View data (project.View, project.Tables, etc) is populated by default values when project is first saved to MPP format.
var attr = ExtendedAttributeDefinition.CreateTaskDefinition(CustomFieldType.Text, ExtendedAttributeTask.Text1, "Custom Field");
project.ExtendedAttributes.Add(attr);
foreach (var item in project.RootTask.Children)
{
var attribute = attr.CreateExtendedAttribute("Test value");
item.ExtendedAttributes.Add(attribute);
}
var table = project.Tables.FirstOrDefault(t => t.Name == "&Entry"); // Table of Gantt chart view which is displayed by default when MPP file is opened.
// Adding column
table.TableFields.Add(new TableField()
{
Field = Field.TaskText1,
Title = "Task Text1",
Width = 20
});
project.Save(@"output.mpp", new MPPSaveOptions()
{
WriteViewData = true // WriteViewData flag should be specified to save changes in TableFields.
});
THX for your reply, im fully known this point.
btw, why does it save mpp twice?
@Jiangqiming
Since you`re opening file from XML view info (View, Table, Filters, etc) is missing in the project.
View data (project.View, project.Tables, etc) is populated by default values when project is first saved to MPP format.
We will improve this scenario to avoid double call of Save method.