All docs
V20.2
20.2
20.1
The page you are viewing does not exist in version 20.1. This link will take you to the root page.
19.2
The page you are viewing does not exist in version 19.2. This link will take you to the root page.
19.1
The page you are viewing does not exist in version 19.1. This link will take you to the root page.
18.2
The page you are viewing does not exist in version 18.2. This link will take you to the root page.
18.1
The page you are viewing does not exist in version 18.1. This link will take you to the root page.
17.2
The page you are viewing does not exist in version 17.2. This link will take you to the root page.

How to: Load Document Properties

  • 2 minutes to read

The Word Processing Document API allows you to load the document metadata (document properties) without loading the document itself. You can use the retrieved information to search for a specific document, catalogue files or collect statistics.

In this example, the information is used to sort documents by their modification date. Call the RichEditDocumentServerExtensions.LoadDocumentProperties method for each file in the folder. Check the Modified property and copy the file to the corresponding folder to sort it by tis modification date.

IMPORTANT

The RichEditDocumentServerExtensions class is defined in the DevExpress.Docs.v20.2.dll assembly. Add this assembly to your project to use the RichEditDocumentServerExtensions functionality. You need a license to the DevExpress Office File API or DevExpress Universal Subscription to use this library in production code. For pricing information, refer to the following page: DevExpress Subscription.

using DevExpress.XtraRichEdit;
using DevExpress.XtraRichEdit.API.Native;
using System;
using System.IO;
using System.Diagnostics;

static void Main(string[] args)
{
    DirectoryInfo directoryInfo = 
    new DirectoryInfo(@"C:\Users\Public\Documents\DevExpress Demos 20.2\Components\Data");
    FileInfo[] files = directoryInfo.GetFiles("*.docx");
    foreach (FileInfo file in files)
    {
        SortDocuments(file.FullName, file.Name);
    }
    Process.Start("explorer.exe", @"C:\Documents");
}

public static void SortDocuments(string filePath, string fileName)
{
    RichEditDocumentServer wordProcessor = new RichEditDocumentServer();

    //Load the metadata from the specified document:
    ReadOnlyDocumentProperties docProperties = 
    wordProcessor.LoadDocumentProperties(filePath);
    DateTime date = docProperties.BuiltIn.Modified;

    //Check the year the document was last modified,
    //And copy the file to the corresponding folder:
    switch (date.Year)
    {
        case 2017:
            File.Copy(filePath, string.Format("C://Documents//2017//{0}", fileName), true);
            break;
        case 2018:
            File.Copy(filePath, string.Format("C://Documents//2018//{0}", fileName), true);
            break;
        case 2019:
            File.Copy(filePath, string.Format("C://Documents//2019//{0}", fileName), true);
            break;
        case 2020:
            File.Copy(filePath, string.Format("C://Documents//2020//{0}", fileName), true);
            break;
    }
}