How to update Ref fields using .NET

I have a document with REF fields nested in IF statements.


I want to programmatically evaluate both the REF and IF fields, so all that’s left is the result of the IF condition. If I save as pdf, the rednering engine takes care of this and all works fine…but I want to do this programmatically and still be left with a usable Aspose Words Document object.

I have tried calling UpdatePageLayout, as the documentation suggests…but that doesn’t seem to do the trick.

I tried calling UpdatePageLayout, then visiting all the REF fields in the document and removing all nodes except the ones between FieldSeparator and FieldEnd (the current evaluated REF’d value). That works well…but then my IF conditions are left in a state like

IF A = “A” “TRUE” "FALSE"

which doesn’t work because the evaluated REF field (A) is not enclosed in quotes. I can’t blindly enclose all evaluated REF fields in quotes…because they may or may not be inside an IF condition…and the quotes are only appropriate if they are inside the condition.

How can/should I accomplish this?

Thanks.

Hi Jeff,

Thanks for your query. Please call UpdateFields() method before saving the document.
It would be great if you please share your sample document for investigation purposes.

Thanks. I ended up calling UpdateFields, then using ConvertFieldsToStaticText to extract the updated value and remove the REF field itself.

Hi Jeff,

Thanks for your feedback. Please let us know if you have any more queries.