Hi,
Dim project As New Project(“New Project 2010.mpp”)
Dim textAttr As New ExtendedAttributeDefinition()
textAttr.FieldId = ExtendedAttributeTask.Text1.ToString(“D”)
textAttr.[Alias] = “New text attribute”
textAttr.CfType = CustomFieldType.Text
textAttr.LookupUid = Guid.NewGuid().ToString()
textAttr.ValueList = New List(Of Value)()
Dim v As New Value()
v.Val = “TEXT VALUE1”
v.Description = “Text value description”
v.Id = 1
textAttr.ValueList.Add(v)
v = New Value()
v.Val = “TEXT VALUE2”
v.Description = “Text value description”
v.Id = 2
textAttr.ValueList.Add(v)
project.ExtendedAttributes.Add(textAttr)
project.Save(“Combo.mpp”, SaveFileFormat.MPP)
string newFile = @"c:\users\sanjay.quadwave\documents\visual studio 2015\Projects\MyTasks\ConsoleApplication1\MigrationPlanTemplate.mpp";
string resultFile = "C:\\OutputMPP.mpp";
Project project = new Project(newFile);
int fieldId = 188743731;
// Add new text3 extended attribute and one text value
ExtendedAttributeDefinition taskTextAttr = new ExtendedAttributeDefinition();
taskTextAttr.Alias = "New text3 attribute";
taskTextAttr.FieldName = "Text3";
taskTextAttr.FieldId = ExtendedAttributeTask.Text3.ToString("D");
taskTextAttr.ElementType = ElementType.Task;
taskTextAttr.CfType = CustomFieldType.Text;
project.ExtendedAttributes.Add(taskTextAttr);
Value textVal = new Value();
textVal.Id = 1;
textVal.Description = "Text value descr";
textVal.Val = "Text value1";
taskTextAttr.ValueList.Add(textVal);
// Add new cost1 extended attribute and two cost values
ExtendedAttributeDefinition taskCostAttr = new ExtendedAttributeDefinition();
taskCostAttr.Alias = “New cost1 attribute”;
taskCostAttr.FieldName = “Cost1”;
taskCostAttr.ElementType = ElementType.Task;
taskCostAttr.CfType = CustomFieldType.Cost;
taskCostAttr.FieldId = ExtendedAttributeTask.Cost1.ToString(“D”);
taskCostAttr.LookupUid = Guid.NewGuid().ToString();
Value costVal1 = new Value();
costVal1.Id = 2;
costVal1.Description = "Cost value 1 descr";
costVal1.Val = "99900";
Value costVal2 = new Value();
costVal2.Id = 3;
costVal2.Description = "Cost value 2 descr";
costVal2.Val = "11100";
taskCostAttr.ValueList.Add(costVal1);
taskCostAttr.ValueList.Add(costVal2);
project.ExtendedAttributes.Add(taskCostAttr);
// Add new task and assign attribute value
Task task = project.RootTask.Children.Add("New task");
ExtendedAttribute taskAttr = new ExtendedAttribute();
taskAttr.AttributeDefinition = taskCostAttr;
taskAttr.Value = "99900";
taskAttr.FieldId = taskCostAttr.FieldId;
task.ExtendedAttributes.Add(taskAttr);
ExtendedAttribute taskAttrText = new ExtendedAttribute();
taskAttrText.AttributeDefinition = taskTextAttr;
taskAttrText.Value = "99900";
taskAttrText.FieldId = taskTextAttr.FieldId;
task.ExtendedAttributes.Add(taskAttrText);
//Save the project as MPP project file
project.Save(resultFile, Aspose.Tasks.Saving.SaveFileFormat.MPP);
Hi Sunjay,
Dim path As String = “”
Dim newFile As String = path & Convert.ToString(“Blank2010.mpp”)
Dim resultFile As String = path & Convert.ToString(“UserOutputMPP.mpp”)
Dim project As New Project(newFile)
’ Add new text3 extended attribute and one text value
Dim taskTextAttr As New ExtendedAttributeDefinition()
taskTextAttr.[Alias] = “New text3 attribute”
taskTextAttr.FieldName = “Text3”
taskTextAttr.FieldId = Convert.ToInt32(ExtendedAttributeTask.Text3).ToString()
taskTextAttr.LookupUid = Guid.NewGuid().ToString()
taskTextAttr.ElementType = ElementType.Task
taskTextAttr.CfType = CustomFieldType.Text
project.ExtendedAttributes.Add(taskTextAttr)
Dim textVal As New Value()
textVal.Id = 1
textVal.Description = “Text value descr”
textVal.Val = “Text value1”
taskTextAttr.ValueList.Add(textVal)
’ Add new cost1 extended attribute and two cost values
Dim taskCostAttr As New ExtendedAttributeDefinition()
taskCostAttr.[Alias] = “New cost1 attribute”
taskCostAttr.FieldName = “Cost1”
taskCostAttr.ElementType = ElementType.Task
taskCostAttr.CfType = CustomFieldType.Cost
taskCostAttr.FieldId = Convert.ToInt32(ExtendedAttributeTask.Cost1).ToString()
taskCostAttr.LookupUid = Guid.NewGuid().ToString()
Dim costVal1 As New Value()
costVal1.Id = 2
costVal1.Description = “Cost value 1 descr”
costVal1.Val = “99900”
Dim costVal2 As New Value()
costVal2.Id = 3
costVal2.Description = “Cost value 2 descr”
costVal2.Val = “11100”
taskCostAttr.ValueList.Add(costVal1)
taskCostAttr.ValueList.Add(costVal2)
project.ExtendedAttributes.Add(taskCostAttr)
’ Add new task and assign attribute value
Dim task As Aspose.Tasks.Task = project.RootTask.Children.Add(“New task”)
Dim taskAttr As New ExtendedAttribute()
taskAttr.AttributeDefinition = taskCostAttr
taskAttr.Value = “99900”
taskAttr.FieldId = taskCostAttr.FieldId
taskAttr.ValueGuid = Guid.NewGuid().ToString()
task.ExtendedAttributes.Add(taskAttr)
Dim taskAttrText As New ExtendedAttribute()
taskAttrText.AttributeDefinition = taskTextAttr
taskAttrText.Value = “Text value1”
taskAttrText.FieldId = taskTextAttr.FieldId
taskAttrText.ValueGuid = Guid.NewGuid().ToString()
task.ExtendedAttributes.Add(taskAttrText)
'Save the project as MPP project file
project.Save(resultFile, Aspose.Tasks.Saving.SaveFileFormat.MPP)
However, I have observed, that values assigned to these attributes for a task are not visible in MSP. This issue is logged under Id: TASKS-34186 for further investigation by the product team. I shall write here as soon some feedback is received in this regard.
The issues you have found earlier (filed as TASKS-34186) have been fixed in this update.
This message was posted using Notification2Forum from Downloads module by Aspose Notifier.