Articles in this section
Category / Section

How to insert author's name in a Word document?

2 mins read

Syncfusion Essential DocIO is a .NET Core Word library used to create, read, and edit Word documents programmatically without Microsoft Word or Interop dependencies. Using this library, you can insert author’s name in a Word document in C#.

Steps to insert author’s name in a Word document:

  1. Create a new C# .NET Core console application project. Create .NET Core console application in Visual Studio in ASP.NET Core Word
  2. Install the Syncfusion.DocIO.Net.Core NuGet package as a reference to your .NET Core applications from NuGet.org.Add DocIO.Net.Core NuGet packages of ASP.NET Core Word
  3. Include the following namespace in the Program.cs file.

C#

using Syncfusion.DocIO;
using Syncfusion.DocIO.DLS;
  1. Use the following code example to insert author’s name in a Word document.

C#

using (FileStream fileStream = new FileStream(Path.GetFullPath(@"../../../Template.docx"), FileMode.Open, FileAccess.ReadWrite))
{
    //Open the template document. 
    using (WordDocument document = new WordDocument(fileStream, FormatType.Automatic))
    {
        //Get the section in a Word document.
        IWSection section = document.LastSection;
        //Add paragraph to the document section.
        IWParagraph paragraph = section.AddParagraph();
        paragraph.AppendText("Author: ");
        //Add field to represent Author from document properties.
        paragraph.AppendField("Author", FieldType.FieldDocProperty);
        //Update the fields in Word document.
        document.UpdateDocumentFields();        
        //Create file stream.
        using (FileStream outputStream = new FileStream(Path.GetFullPath(@"../../../Result.docx"), FileMode.Create, FileAccess.ReadWrite))
        {
            //Save the Word document to file stream.
            document.Save(outputStream, FormatType.Docx);
        }
    }
}

A complete working sample to insert author’s name in a Word document in C# can be downloaded from GitHub.

By executing the program, you will get the Output document as follows.

Output document generated in ASP.NET Core Word 

Take a moment to peruse the documentation, where you can find basic Word document processing options along with the features like mail mergemerge and split documents, find and replace text in the Word document, protect the Word documents, and most importantly, the PDF and Image conversions with code examples.

Explore more about the rich set of Syncfusion Word Framework features.

See Also:

Is it possible to update Include Text field in Word document using Essential DocIO?

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied