Extract Document Metadata

This module uses the DevExpress Word Processing Document API to read and extract metadata from the document. You can process the predefined sample file or supply your own document. To do the latter, select Upload a File in the file selection drop-down menu.

Select required metadata types in the panel below. Click Read Document Metadata to download a TXT file with extracted information.

Select a Document
Sample.docx



using DevExpress.XtraRichEdit;
using System.Text;

string ReadDocumentPropertiest(Stream inputStream, bool readDocumentProperties, bool readCustomProperties) {
    var output = new StringBuilder();

    using var wordProcessor = new RichEditDocumentServer();
    wordProcessor.LoadDocument(inputStream);

    var document = wordProcessor.Document;

    if (readDocumentProperties) {
        // Core Properties
        var coreProperties = document.DocumentProperties;
        output.AppendLine("CORE DOCUMENT PROPERTIES:");
        output.AppendLine(new string('-', 30));
        output.AppendLine($"Title: {coreProperties.Title ?? ""}");
        output.AppendLine($"Author: {coreProperties.Author ?? ""}");
        output.AppendLine($"Subject: {coreProperties.Subject ?? ""}");
        output.AppendLine($"Keywords: {coreProperties.Keywords ?? ""}");
        output.AppendLine($"Category: {coreProperties.Category ?? ""}");
        output.AppendLine($"Company: {coreProperties.Company ?? ""}");
        output.AppendLine($"Manager: {coreProperties.Manager ?? ""}");
        output.AppendLine($"Created Date: {coreProperties.Created.ToString("yyyy-MM-dd HH:mm:ss")}");
        output.AppendLine($"Last Printed: {coreProperties.LastPrinted.ToString("yyyy-MM-dd HH:mm:ss")}");
        output.AppendLine();
    }

    if (readCustomProperties) {
        var customProperties = document.CustomProperties;

        output.AppendLine("CUSTOM PROPERTIES:");
        output.AppendLine(new string('-', 30));

        // Check if there are any custom properties
        var hasCustomProperties = false;
        var customPropsList = new List<string>();

        foreach (string propName in customProperties.Names) {
            hasCustomProperties = true;
            var propValue = customProperties[propName];
            var valueStr = propValue?.ToString() ?? "";
            var typeStr = propValue?.GetType().Name ?? "String";
            customPropsList.Add($"{propName}: {valueStr} ({typeStr})");
        }
        if (!hasCustomProperties)
            output.AppendLine("No custom properties found.");
        else
            foreach (var customProp in customPropsList)
                output.AppendLine(customProp);
        output.AppendLine();
    }

    return output.ToString();
}