Thanks for your request. I cannot reproduce the problem on my side using the latest version of Aspose.Words (9.4.0). I use the following code for testing:
Document doc = new Document("in.doc");
// Loop through all Field Names
foreach(string fieldName in doc.MailMerge.GetFieldNames())
{
Console.WriteLine(fieldName);
}
Thank you for additional information. I managed to reproduce the problem on my side. Your request has been linked to the appropriate issue. You will be notified as soon as it is fixed.
It seems there is something wrong with these MergeFields. If you for example try renaming them and save, the problem disappears.
Best regards,
Thanks for your request. Unfortunately, I cannot provide you any reliable estimate regarding this issue at the moment. But I think you can try parsing field code to retrieve correct field name. Please see the following code example which shows how to get field code:
Document doc = new Document("Testing+.doc");
// Get collection of FieldStarts
NodeCollection fieldStarts = doc.GetChildNodes(NodeType.FieldStart, true, false);
// Loop through all Field Starts
foreach(FieldStart fieldStart in fieldStarts)
{
if (fieldStart.FieldType.Equals(FieldType.FieldMergeField))
{
Console.WriteLine(GetFieldCode(fieldStart));
}
}
private static string GetFieldCode(FieldStart fieldStart)
{
StringBuilder builder = new StringBuilder();
for (Node node = fieldStart; node != null && node.NodeType != NodeType.FieldSeparator && node.NodeType != NodeType.FieldEnd; node = node.NextPreOrder(node.Document))
{
// Use text only of Run nodes to avoid duplication.
if (node.NodeType == NodeType.Run)
builder.Append(node.GetText());
}
return builder.ToString();
}
If you need any further assistance, please feel free to ask.
Best regards,