Free Support Forum - aspose.com

Locking Fields before they get updated

Hello!

My company is using a Word to PDF to TIFF process that relies on Word.Interop. The problem with it is that date fields are auto-updating and we can’t seem to disable that before they get updated. I worked with Aspose before, but I’m not sure about this part. When Apsose.Words loads a document, does it update auto-update fields? If so, is there a way to disable that for a document?

Thanks!

Hi Doug,


Thanks for your inquiry. Sure, you can lock field by using the following code snippet (field should not recalculate its result upon calling UpdateFields method).

Document doc = new
Document(@“C:\Temp\in.docx”);

foreach (FieldStart start in doc.GetChildNodes(NodeType.FieldStart, true))

{

if (start.FieldType == FieldType.FieldDate)

start.IsLocked = true;

}

doc.UpdateFields();

doc.Save(@"C:\Temp\out.docx");


I hope, this helps.

Best regards,

At the beginning there, when Document doc = new Document(@“C:\Temp\in.docx”); is executed, do fields get updated on open? If so, can that be disabled? I don’t want to lose the value in the field when I open the document.

Hi Doug,


Thanks for your inquiry.

No, when you open, modify and then save a document, Aspose.Words does not update fields automatically, it keeps them intact. Therefore, you would usually want to call Document.UpdateFields method before saving if you have modified the document programmatically and want to make sure the proper (calculated) field values appear in the saved document. However, it does not update the fields that you have explicitly locked .

Best regards,