How to set Word Document Properties?

Word document properties show a brief description about the document. Through properties, we can get general information about this document, such as document size, location, date of created and so on. Also, we can set advanced properties by ourselves, for example, adding document title, author information, category, keywords, comment, etc. This guide introduces a solution of how to set word document properties in C# via Spire.Doc for .NET.

The following screenshot shows the result after setting properties.

Summary Properties Custom Properties

Download Spire.Doc and install it on your system. Then adds Spire.Doc.dll as reference in the downloaded Bin folder though the below path: "..\Spire.Doc\Bin\NET4.0\ Spire.Doc.dll".

Now it comes to the steps of how to set word document properties.

Step 1: Load a word document from the file.

Document document = new Document();

Step 2: Set Word document Properties.

We have BuiltinDocumentProperties and CustomDocumentProperties to add properties to the word document. We cannot add or remove built-in document properties; we can just change their values. We can use CustomDocumentProperties.Add and CustomDocumentProperties.Remove to add and remove the custom properties.

//Add the build-in Properties.
document.BuiltinDocumentProperties.Title = "Document Demo Document";
document.BuiltinDocumentProperties.Author = "James";
document.BuiltinDocumentProperties.Company = "e-iceblue";
document.BuiltinDocumentProperties.Keywords = "Document, Property, Demo";
document.BuiltinDocumentProperties.Comments = "This document is just a demo.";

//Add the custom properties.
CustomDocumentProperties custom = document.CustomDocumentProperties;
custom.Add("e-iceblue", true);
custom.Add("Authorized By", "John Smith");
custom.Add("Authorized Date", DateTime.Today);

//Remove the custom properties:
Document document = new Document("Sample.doc");

Step 3: Save the document to file.