Recursive AI

Read a DOCX file’s title and author in C#

OneDocument is a free, open-source Word, Excel and PowerPoint document library for .NET from Recursive AI. MIT or Apache-2.0, no native dependencies.

Use sample.docx from the zip. Word doesn’t need to be installed.

Terminal
dotnet add package RecursiveAI.OneDocument.Documents

Requires .NET 10 (net10.0); .NET 9 and earlier aren’t supported.

C#
using RecursiveAI.OneDocument.Documents;
using var doc = Document.Open("sample.docx");
var core = doc.Properties.Core;
Console.WriteLine($"Title: {core.Title}");
Console.WriteLine($"Author: {core.Creator}");

Unzip the example, then dotnet run.

Text
Title: Trail notes
Author: Casey Nguyen

The full program

C#
using RecursiveAI.OneDocument.Documents;
 
using var doc = Document.Open("sample.docx");
var core = doc.Properties.Core;
Console.WriteLine($"Title: {core.Title}");
Console.WriteLine($"Author: {core.Creator}");
Console.WriteLine($"Subject: {core.Subject}");
Console.WriteLine($"Last saved by: {core.LastModifiedBy}");

dotnet run prints:

Text
Title: Trail notes
Author: Casey Nguyen
Subject: Weekend route
Last saved by: Jordan Lee

The sample’s body starts with “Pack water and a trail map.” The values printed here come from a separate XML file inside the DOCX, docProps/core.xml. Here’s an excerpt:

XML
<dc:title>Trail notes</dc:title>
<dc:creator>Casey Nguyen</dc:creator>
<dc:subject>Weekend route</dc:subject>
<cp:lastModifiedBy>Jordan Lee</cp:lastModifiedBy>

An unset title or author is null; OneDocument doesn’t fill it in from the file name or body text.

Variations

Label missing metadata. Replace the two print lines in the snippet at the top with these if you want an explicit fallback:

C#
Console.WriteLine(core.Title ?? "(no title saved)");
Console.WriteLine(core.Creator ?? "(no author saved)");

The short answer

Open the DOCX with Document.Open, then read doc.Properties.Core.Title and doc.Properties.Core.Creator. Creator is the stored author. You don’t need to run Microsoft Word or extract text from the pages; the two values are read from the file’s core properties. The sample records Casey Nguyen as the author and Jordan Lee as the last person to save it, so those two fields print different names.

How do I view the author of a Word document in C#?

Read Creator, not LastModifiedBy. In the package, Creator maps to dc:creator, while LastModifiedBy maps to cp:lastModifiedBy. If the file has been edited and saved by someone else, both values may be useful. Label them separately rather than treating them as two names for the same field. Both are stored values, not proof of who wrote any particular text. The author attached to a tracked change is a separate record; see tracked changes if you need that information.

If Creator is missing, leave the result blank or give it an explicit label as in the variation. Don’t use the last editor as the missing author: doing so mixes two distinct properties.

How can I check the metadata for a DOCX file?

Start with Properties.Core for common fields such as title, subject, author, and keywords. The title field is not the file name and is not the first heading: in the example sample.docx, Trail notes, and Pack water and a trail map. are three different strings. Decide which value your index or display actually needs before choosing what to read.

The document properties guide distinguishes the core, application, and custom property parts. Use the core part for title and author. A custom property is a named field added by an application or user, such as a project code; it belongs in Properties.Custom, not in the core title or subject. The program above only reads properties. It never calls SaveAs, so it doesn’t write a new copy or update the file’s metadata.

All onedocument recipes