Document properties
The properties Word shows under File > Info — title, subject, author, keywords (Tags), comments and category — live
in the package part docProps/core.xml. DocWright carries that part through a load and a save untouched; these two
calls read it and change it.
DocumentCoreProperties properties = document.ReadCoreProperties();
Console.WriteLine(properties.Title ?? "(no title)");
DocumentEdit edit = document.SetCoreProperties(DocumentPosition.StartOf(paragraph), p =>
{
p.Title = "Quarterly report";
p.Creator = "Ada Lovelace; Grace Hopper"; // several authors: one value, semicolons
p.Keywords = "budget, forecast";
p.Category = string.Empty; // cleared
p.Subject = null; // removed
});
| Value | Written |
|---|---|
| a string | the element with that text |
"" |
the element, empty: what Word writes when a property is cleared (WQ-0124) |
null |
the element removed |
What to know
- It is one undoable
DocumentEdit; it reports no changed paragraphs, so nothing is laid out again. - The part is rewritten in place: Word's revision number, the created and modified dates, the last author and any element DocWright does not name are kept. DocWright does not bump them.
- A document without the part gets one, with its package relationship.
- A part that cannot be read (it declares a DTD, is larger than 1 MB, or is not XML) reads as no properties; setting replaces it with a well-formed one.
- Manager and Company are not here: they are the extended properties, below.
Manager and Company
Word keeps these two in another part, docProps/app.xml, beside the statistics and the application name it writes
there. They are read and set the same way, as their own edit:
DocumentExtendedProperties app = document.ReadExtendedProperties();
Console.WriteLine(app.Company ?? "(no company)");
DocumentEdit edit = document.SetExtendedProperties(DocumentPosition.StartOf(paragraph), p =>
{
p.Manager = "Grace Hopper";
p.Company = "Example Ltd";
});
The values behave as in the table above, and the rest of the part (template, page and word counts, application) is
kept as it was. Word writes an empty Company element into every new document, so a document from Word reads
Company as "", not null, until someone gives it one (WQ-0131). To change both kinds of property in one undo step,
keep the two edits together and undo them as a pair.