Document Settings

This example demonstrates how to set built-in document properties and add some custom document properties.

Document properties are correct documentation that provides attribution or credit to the original author or creator. It allows someone to find the documents you cited on their own. It enables the reader to follow the continuum of research.

Below are the basic built-in document properties

  • Author
  • ApplicationName
  • Category
  • Comments
  • Company
  • Keywords
  • Manager
  • Subject
  • Title

Apart from basic document we can also define custom properties like:

  • Order Date
  • Order Id
  • Invoice etc.

We have versions of this representation in words ,using dropdown you can make a choice within the following

  • Word Doc
  • Word Docx
  • Word ML
  • RTF
  • MS Text format
  • E-book format
  • DLS based xml file format
  • HTML

After clicking a generate button will launch a file with above choosen version of word with specified properties.

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Text;

using OfficeComponent.Word;

namespace OfficeComponent.Samples
    class DocumentSettingsExample : WordExampleBase
        public DocumentSettingsExample(string commonDataPath, string outputDir)
            : base(commonDataPath, outputDir)


        public DocumentSettingsExample(string commonDataPath, string outputDir, string xmlFile) : base(commonDataPath, outputDir, xmlFile)


        public override string Execute()
            WordDocument document = new WordDocument();

            #region Document Properties

            // Document Properties
            document.BuiltinDocumentProperties.Author = "John Smith";
            document.BuiltinDocumentProperties.ApplicationName = "Document Settings";
            document.BuiltinDocumentProperties.Category = "OfficeComponent Word Examples";
            document.BuiltinDocumentProperties.Comments = "Copyright OfficeComponent";
            document.BuiltinDocumentProperties.Company = "OfficeComponent Division, OfficeComponent";
            document.BuiltinDocumentProperties.Keywords = "Document Settings";
            document.BuiltinDocumentProperties.Manager = "My Manager";
            document.BuiltinDocumentProperties.Subject = "Setting document properties without using MS Word";
            document.BuiltinDocumentProperties.Title = "Document Settings";

            // Remove a custom property

            // Add custom document properties
            document.CustomDocumentProperties.Add("Order_Date", DateTime.Today);
            document.CustomDocumentProperties.Add("Order_ID", 12345);


            #region Add Text

            Section section = document.AddSection();
            Paragraph paragraph = section.AddParagraph();
            TextRange text = paragraph.AppendText("To view the Document Properties, open File -> Properties -> Summary/Custom.");
            text.CharacterFormat.FontName = "Calibri";
            text.CharacterFormat.FontSize = 15;


            string fileName = Path.Combine(OutputDir, this.GetType().Name + "_" + Guid.NewGuid().ToString() + GetExtension(SaveAsFormat));
            // Save the document.
            document.Save(fileName, SaveAsFormat);

            // Close the document.

            return fileName;

Imports System.Drawing.Imaging
Imports System.IO
Imports System.Text

Imports OfficeComponent.Word

Namespace OfficeComponent.Samples
	Friend Class DocumentSettingsExample
		Inherits WordExampleBase
		Public Sub New(ByVal commonDataPath As String, ByVal outputDir As String)
			MyBase.New(commonDataPath, outputDir)

		End Sub

		Public Sub New(ByVal commonDataPath As String, ByVal outputDir As String, ByVal xmlFile As String)
			MyBase.New(commonDataPath, outputDir, xmlFile)

		End Sub

		Public Overrides Function Execute() As String
			Dim document As New WordDocument()

'			#Region "Document Properties"

			' Document Properties
			document.BuiltinDocumentProperties.Author = "John Smith"
			document.BuiltinDocumentProperties.ApplicationName = "Document Settings"
			document.BuiltinDocumentProperties.Category = "OfficeComponent Word Examples"
			document.BuiltinDocumentProperties.Comments = "Copyright OfficeComponent"
			document.BuiltinDocumentProperties.Company = "OfficeComponent Division, OfficeComponent"
			document.BuiltinDocumentProperties.Keywords = "Document Settings"
			document.BuiltinDocumentProperties.Manager = "My Manager"
			document.BuiltinDocumentProperties.Subject = "Setting document properties without using MS Word"
			document.BuiltinDocumentProperties.Title = "Document Settings"

			' Remove a custom property

			' Add custom document properties
			document.CustomDocumentProperties.Add("Order_Date", Date.Today)
			document.CustomDocumentProperties.Add("Order_ID", 12345)

'			#End Region

'			#Region "Add Text"

			Dim section As Section = document.AddSection()
			Dim paragraph As Paragraph = section.AddParagraph()
			Dim text As TextRange = paragraph.AppendText("To view the Document Properties, open File -> Properties -> Summary/Custom.")
			text.CharacterFormat.FontName = "Calibri"
			text.CharacterFormat.FontSize = 15

'			#End Region

			Dim fileName As String = Path.Combine(OutputDir, Me.GetType().Name & "_" & Guid.NewGuid().ToString() & GetExtension(SaveAsFormat))
			' Save the document.
			document.Save(fileName, SaveAsFormat)

			' Close the document.

			Return fileName
		End Function
	End Class

End Namespace