Hello…
An example is like this:
I create a custom header named “Test 01/03/2013”. How i can create this with ASPOSE Tasks???
Hi,
lic.SetLicense(“Aspose.Tasks.lic”)
Dim prj As Project
Dim reader As ProjectReader
Dim writer As ProjectWriter
Dim ead As ExtendedAttributeDefinition
Dim ea As ExtendedAttribute
‘read project data from xml
reader = New ProjectReader()
prj = reader.Read(“project2.mpp”)
‘add extended attribute definition
ead = New ExtendedAttributeDefinition()
ead.FieldName = “Text1”
ead.Alias = “Description”
ead.FieldId = CType(ExtendedAttributeTask.Text1, Integer).ToString
prj.ExtendedAttributes = New ArrayList()
prj.ExtendedAttributes.Add(ead)
For Each task As Task In prj.RootTask.Children
task.ExtendedAttribute = New ArrayList()
ea = New ExtendedAttribute()
ea.FieldId = ead.FieldId
ea.Value = String.Format("Description of ’{0}’.", task.Name)
task.ExtendedAttribute.Add(ea)
Next
prj.Save(“project_res.mpp”, Aspose.Tasks.Saving.SaveFileFormat.MPP)
Perfect… i test that code, but in C#, and works as you said.
I create the template test MPP file (with out custom fields) and i read it without problem. After of this i add some tasks and i wanted save in the same format, in this case MPP, but the code throw me the following error:
"The operation is not allowed in evaluation mode"
Hi,
Following is the sample code which can be used to access the extended attribute “Description” from the above example, update the extended attribute for each task and then save back on the disc.
Please give it a try and let us know your feedback.
static void UpdateExtendedAttribute()
{
//create a project reader instance
ProjectReader rdr = new ProjectReader();
//call read method of project reader object to get project object
Project project = rdr.Read(@"Tasks_448660\project_res.mpp");
foreach (Task tsk in project.RootTask.Children)
{
FilterByAlias filter = new FilterByAlias("Description");
ExtendedAttribute attr = ArrayUtils.Find(tsk.ExtendedAttribute, filter) as ExtendedAttribute;
attr.Value = "New Value for " + tsk.Name;
}
//Recalculate the Project now
project.CalcTaskIds();
project.CalcTaskUids();
project.UpdateReferences();
project.Save(@"Tasks_448660\project_res.mpp", Aspose.Tasks.Saving.SaveFileFormat.MPP);
}
private class FilterByAlias : ICondition
{
private string alias;
public FilterByAlias(string alias)
{
this.alias = alias.ToUpper(CultureInfo.InvariantCulture).Trim();
}
public bool Check(object el)
{
ExtendedAttribute attr = el as ExtendedAttribute;
if (attr == null || attr.AttributeDefinition == null || attr.AttributeDefinition.Alias == null)
return false;
return (attr.AttributeDefinition.Alias.ToUpper(CultureInfo.InvariantCulture).Trim() == alias);
}
}
In order to avoid the evaluation error, you can get a 30 day Temporary License by visiting this link. Please apply for a temporary license and let us know if we can be of any additional help to you.
Works very well the code to read the custom headers. About the license, i got one and my code works now… thanks.