Word File Properties

Document can contain built-in and custom properties.

Following sample shows how to read built-in and custom document properties.

Screenshot

Document Properties Screenshot

See the full code below, use RUN EXAMPLE to execute.

Upload your file (Drag files here)

1using System;
2using System.IO;
3using System.Linq;
4using GemBox.Document;
5using GemBox.Document.Drawing;
6
7class Sample
8{
9    [STAThread]
10    static void Main(string[] args)
11    {
12        // If using Professional version, put your serial key below.
13        ComponentInfo.SetLicense("FREE-LIMITED-KEY");
14
15        DocumentModel document = DocumentModel.Load("Reading.docx");
16
17        Paragraph builtInPara = new Paragraph(document,
18            new Run(document, "Built-in document properties:"),
19            new SpecialCharacter(document, SpecialCharacterType.LineBreak));
20        builtInPara.ParagraphFormat.Alignment = HorizontalAlignment.Left;
21
22        foreach (var docProp in document.DocumentProperties.BuiltIn)
23        {
24            builtInPara.Inlines.Add(
25                new Run(document, string.Format("{0}: {1}", docProp.Key, docProp.Value)));
26
27            builtInPara.Inlines.Add(new SpecialCharacter(document, SpecialCharacterType.LineBreak));
28        }
29
30        Paragraph customPropPara = new Paragraph(document,
31            new Run(document, "Custom document properties:"),
32            new SpecialCharacter(document, SpecialCharacterType.LineBreak));
33        customPropPara.ParagraphFormat.Alignment = HorizontalAlignment.Left;
34
35        foreach (var docProp in document.DocumentProperties.Custom)
36        {
37            customPropPara.Inlines.Add(
38                new Run(document, string.Format("{0}: {1} (Type: {2})", docProp.Key, docProp.Value, docProp.Value.GetType())));
39
40            customPropPara.Inlines.Add(new SpecialCharacter(document, SpecialCharacterType.LineBreak));
41        }
42
43        document.Sections.Clear();
44        document.Sections.Add(new Section(document, builtInPara, customPropPara));
45
46        document.Save("Document Properties.docx");
47    }
48}
1Imports System
2Imports System.IO
3Imports System.Linq
4Imports GemBox.Document
5Imports GemBox.Document.Drawing
6
7Module Samples
8
9    Sub Main()
10
11        ' If using Professional version, put your serial key below.
12        ComponentInfo.SetLicense("FREE-LIMITED-KEY")
13
14        Dim document As DocumentModel = DocumentModel.Load("Reading.docx")
15
16        Dim builtInPara As New Paragraph(document,
17                                New Run(document, "Built-in document properties:"),
18                                New SpecialCharacter(document, SpecialCharacterType.LineBreak))
19        builtInPara.ParagraphFormat.Alignment = HorizontalAlignment.Left
20
21        For Each docProp As KeyValuePair(Of BuiltInDocumentProperty, String) In document.DocumentProperties.BuiltIn
22
23            builtInPara.Inlines.Add(
24                New Run(document, String.Format("{0}: {1}", docProp.Key, docProp.Value)))
25
26            builtInPara.Inlines.Add(
27                New SpecialCharacter(document, SpecialCharacterType.LineBreak))
28
29        Next
30
31        Dim customPropPara As New Paragraph(document,
32                                New Run(document, "Custom document properties:"),
33                                New SpecialCharacter(document, SpecialCharacterType.LineBreak))
34        customPropPara.ParagraphFormat.Alignment = HorizontalAlignment.Left
35
36        For Each docProp As KeyValuePair(Of String, Object) In document.DocumentProperties.Custom
37
38            customPropPara.Inlines.Add(
39                New Run(document, String.Format("{0}: {1} (Type: {2})", docProp.Key, docProp.Value, docProp.Value.GetType())))
40
41            customPropPara.Inlines.Add(
42                New SpecialCharacter(document, SpecialCharacterType.LineBreak))
43
44        Next
45
46        document.Sections.Clear()
47        document.Sections.Add(New Section(document, builtInPara, customPropPara))
48
49        document.Save("Document Properties.docx")
50
51    End Sub
52
53End Module

Check next sample or find out more about GemBox.Document and GemBox Software.