Thanks for your inquiry. Please call the Document.UpdateFields method before FieldsHelper.ConvertFieldsToStaticText as shown below to get the desired output.
For future reference, is there any reason it was picking up the Created Date? It’s a little worrying that the helper picks the wrong date without updating.
After some testing, it appears your solution is not going to work for us. In our process we copy the document into a temp folder for processing. Running UpdateFields() would also update:
{ FILENAME \p \* MERGEFORMAT }
which is not acceptable for us as it must keep that printed value. Any help in understanding why it would use the Created Date would be approciated so we know how to handle the situation in the future.
If you notice the current value of the file path is “C:\Program Files (x86)\Aspose\Aspose.Words for .NET\Examples\CSharp\Programming-Documents\Fields\Data\Test Convert SaveDate - Copy.docx”
If we run ConvertFieldsToStaticText it will keep that vlaue, if we update the fields though, it will pick the new filename and file path (not acceptable for what we need). we’d like the FieldSaved date method to work the same, ie to use the value as shown on the document. Again, any insight into understanding why the Creation date is used will help us. Whether or not it uses a preupdate or post update value, it should never use the Creation date I would have thought.
Thanks for your inquiry. A field in a Word document is a complex structure consisting of multiple nodes that include field start, field code, field separator, field result and field end. The content between the field start and separator is the field code. The content between the field separator and field end is the field result. Please refer to the following article. Working with Fields
In your document, the value (field result) of SAVEDATE FIELD is 24.8.2017. This is the reason you are getting this value without updating the field.
In your case, we suggest you please update only SAVEDATE field as shown below. Please use Field.Update method to update only field and Field.Unlink method to unlink field. Hope this helps you.
For the moment I think we’ll Convert the FileName before running an update in case other field types show the same issue.
I’m still confused why the field result is 24.8.2017. When I open the document, it’s always showing 5.9.2017. I don’t have any of the “Update Fields” settings on in Word and I thought they only come in play when you go to print.
With the .Unlink() function, does it have any difference internally to the FieldsHelper? Which is better to use?
Thanks for your inquiry. Please note that Aspose.Words mimics the same behavior as MS Word does. The value “24.8.2017” is stored in your document. Please unzip your document and check footer1.xml and footer2.xml.
MS Word updates this value from built-in document property i.e. last modified. You can get this value using Document.BuiltInDocumentProperties.LastSavedTime property.
Yes, you can use Field.Unlink method instead of FieldsHelper utility.