Creating new autofield


I created a new autofield(author) in a document using the following code. When i open the file in MSWord, the autofield(author) shows empty.After right click and update the field, the author name generates. I need to show the author name when i opened the document.How should do this?

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

Section section = new Section(doc);
Body body = doc.getFirstSection().getBody();

Paragraph currentPara = new Paragraph(doc);
Run currentRun = new Run(doc, "");
builder.insertField("AUTHOR \* MERGEFORMAT");
body.appendChild(currentPara);"src/Output.docx", SaveFormat.DOCX);

Thanks for your request. Unfortunately, currently, Aspose.Words cannot update AUTHOR field in the document. However, Aspose.Words can update DOCPROPERTY fields. So you can use it instead AUTHOR field. Here is field code:
You can set value of Author property using setAuthor.
And then update such field using UpdateField method.
Please try using the following code:

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.insertField("DOCPROPERTY Author \\* MERGEFORMAT");
doc.updateFields();"C:\\Temp\\Autofield.docx", SaveFormat.DOCX);

Best regards,


Thanks for your reply. But the same code works for autofields like date, time,page number and page count. Its updating automatically when i open the document. Why the author name and document name is not working.

Thanks for your request. It is by MS Word design. MS Word automatically updated DATE/PAGE/NUMPAGES etc. fields inside the document Header/Footer during opening. But AUTHOR field is not updated upon opening with MS Word.
Best regards,

The issues you have found earlier (filed as WORDSNET-4680) have been fixed in this .NET update and in this Java update.

This message was posted using Notification2Forum from Downloads module by aspose.notifier.