We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Nested Field Code not Being Preserved

I have a Word 2003 document that contains nested field codes that look like this:

{ INCLUDEPICTURE "\\\\aserver.xyz.com\\Signature\\{ DOCVARIABLE SIGNER_IMAGE }.jpg" \* MERGEFORMAT }

In the simplest case if I open a document that contains these field codes and save it right away, the saved copy does not properly retain the field codes. They end up getting converted into something that looks like this:

{ INCLUDEPICTURE "\\\\aserver.xyz.com\\Signature\\ DOCVARIABLE SIGNER_IMAGE .jpg" \* MERGEFORMAT \d }, with one non-printable character before DOCVARIABLE and two before the .jpg.

I have attached a copy of the Word doc with the original field codes. Below is a snippet of the code that was used to do the save:

Dim oLic As New License

oLic.SetLicense("Aspose.Words.lic")

Dim oDoc As New Document("C:\test\NestedFieldCodes\NestedFieldCodes3.doc")

oDoc.Save("C:\test\NestedFieldCodes\NestedFieldCodes4.doc")

Hi

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for reporting this problem to us. I managed to reproduce it on my side. Your request has been linked to the appropriate issue. You will be notified as soon as it is resolved.

Best regards.

Thanks a lot!

Hello

Thanks for your interest in Aspose.Words. I'm working on the issue you have reported earlier. Let me explain little bit. Upon loading INCLUDEPICTURE field to the DOM (Document Object Model), Aspose.Words converts this field to shape, and that is why your problem occurs (there is no field inside shape). To fix this all that you need it is specify LoadOptions.PreserveIncludePictureField = true, in this case you will be able to replace DOCVARIABLE inside INCLUDEPICTURE field. Please see the following code:

LoadOptions loadOptions = new LoadOptions();

loadOptions.PreserveIncludePictureField = true;

Document doc = new Document("NestedFieldCodes3.doc", loadOptions);

doc.Variables["SIGNER_IMAGE"] = "TestImage";

doc.UpdateFields();

doc.Save("out.doc");

Please let me know in case of any issues, I will be glad to help you.

Best regards,