Append two documents with same docvariable names

Hi!

I’m trying to append two documents with aspose words for .NET 18.2. Both documents started basing on the same template but the template doc variables were populated differently.
Now when I append the second document to the first one using AppendDocument function, the two document start sharing the docvariables values and so show each of them shows the same value.

How can I solve it?

I know that in Word VBA there is the Unlink function which is used to “fix” a field by deleting the field itself and converting the content/result to static content.
See: Fields.Unlink-Methode (Word) | Microsoft Learn

How can I do this with Aspose preserving the formatting?

In other words: before saving each of the document I’d like to remove the doc variable fieldd, but the current content of the docvariable should remain as static text with the same formatting as before so that the document looks like before but the content isn’t related to a doc variable anymore.
In this way I should be able, after saving the documents with this docvariable removal, to append them

Thank you in advance
Luca

@ceck Aspose.Words also provides a similar method Document.UnlinkFields unlinks (replaces with static text) all fields in the document.
Also, you can unlink a particular field using Field.Unlink method.
Both these methods are available in your 18.2 version of Aspose.Words.
In your case you can use code like the following:

foreach (Field f in doc.Range.Fields)
{
    if (f.Start.FieldType == FieldType.FieldDocVariable)
        f.Unlink();
}
1 Like