Hi Christian,
Thanks for your inquiry.
In the mean time while you are waiting for this fix you can use the work around below. There are sufficent API members to very easily implement this update manually. Please see the code below which achieves this.
Document doc = new Document("Testing.docx");<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
doc.UpdateFields();
// Update REF fields with the proper values.
UpdateRefFields(doc);
doc.Save("Testing Out.docx");
public static void UpdateRefFields(CompositeNode node)
{
// The document that this node belongs to.
Document doc = (Document)node.Document;
// Update list labels so we can get the list numbers of the paragraphs.
doc.UpdateListLabels();
// Iterate through all FieldRefs in the Document or CompositeNode. CompositeNode means that this code
// can run on only certain parts of the document e.g a specific section.
foreach (FieldStart start in node.GetChildNodes(NodeType.FieldStart, true))
{
if (start.FieldType == FieldType.FieldRef)
{
// Parse the FieldCode.
Regex regex = new Regex(@"\s*(?\S+)\s+(?\S+)\s+(?.+)"
);
Match match = regex.Match(GetFieldCode(start));
// See if the field contains the switch we are interested in.
if (match.Groups["switches"].Value.Contains("\\r"))
{
// Get the paragraph referenced by this field.
Bookmark bookmark = doc.Range.Bookmarks[match.Groups["bookmark"].Value];
if (bookmark != null)
{
// Get the paragraph that the reference bookmark is contained in.
Paragraph bookmarkPara = (Paragraph)bookmark.BookmarkStart.ParentNode;
// Get the current field result.
string fieldResult = GetFieldResult(start);
// Get the list number of the paragraph which is the proper result for this switch.
string newResult = bookmarkPara.ListLabel.LabelString.TrimEnd('.');
// Replace the current field result with the new result. This should retain formatting.
start.ParentParagraph.Range.Replace(fieldResult, newResult, false, false);
}
}
}
}
}
private static string GetFieldCode(Aspose.Words.Fields.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 the text only of Run nodes to avoid duplication.
if (node.NodeType == NodeType.Run)
builder.Append(node.GetText());
}
return builder.ToString();
}
private static string GetFieldResult(Aspose.Words.Fields.FieldStart fieldStart)
{
StringBuilder builder = new StringBuilder();
bool isAtSeparator = false;
for (Node node = fieldStart; node != null && node.NodeType != NodeType.FieldEnd; node = node.NextPreOrder(node.Document))
{
if (node.NodeType == NodeType.FieldSeparator)
{
isAtSeparator = true;
}
// Use text only of Run nodes to avoid duplication.
if (isAtSeparator && node.NodeType == NodeType.Run)
builder.Append(node.GetText());
}
return builder.ToString();
}
Thanks,