FieldOptionsDefaultDocumentAuthor Property |
Namespace: Aspose.Words.Fields
Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // If we open an existing document, the document's author's full name will be displayed by the field // If we create a document programmatically, we need to set this attribute to the author's name so our field has something to display doc.FieldOptions.DefaultDocumentAuthor = "Joe Bloggs"; builder.Write("This document was created by "); FieldAuthor field = (FieldAuthor)builder.InsertField(FieldType.FieldAuthor, true); field.Update(); Assert.AreEqual(" AUTHOR ", field.GetFieldCode()); Assert.AreEqual("Joe Bloggs", field.Result); // If this property has a value, it will supersede the one we set above doc.BuiltInDocumentProperties.Author = "John Doe"; field.Update(); Assert.AreEqual(" AUTHOR ", field.GetFieldCode()); Assert.AreEqual("John Doe", field.Result); // Our field can also override the document's built in author name like this field.AuthorName = "Jane Doe"; field.Update(); Assert.AreEqual(" AUTHOR \"Jane Doe\"", field.GetFieldCode()); Assert.AreEqual("Jane Doe", field.Result); // The author name in the built in properties was changed by the field, but the default document author stays the same Assert.AreEqual("Jane Doe", doc.BuiltInDocumentProperties.Author); Assert.AreEqual("Joe Bloggs", doc.FieldOptions.DefaultDocumentAuthor); doc.Save(ArtifactsDir + "Field.AUTHOR.docx");