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

  • 3 minutes to read

Use the Workbook.LoadDocumentProperties method to load document metadata (document properties) without loading the workbook itself. You can use the retrieved metadata to search for a specific document, to organize files, or to collect statistics.

IMPORTANT

The Workbook class is defined in the DevExpress.Docs.v20.2.dll assembly. Add this assembly to your project to use the Workbook API. You need a license to the DevExpress Office File API or DevExpress Universal Subscription to use this assembly in production code. Refer to the DevExpress Subscription page for pricing information.

The following example retrieves document properties from workbooks and sorts files by their modification date:

using DevExpress.Spreadsheet;
using System.Diagnostics;
using System.IO;
using System;
// ...

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

private static void SortDocuments(FileInfo file)
{
    using (Workbook workbook = new Workbook())
        {
        // Load metadata from the document.
        ReadOnlyDocumentProperties docProperties = 
            workbook.LoadDocumentProperties(file.FullName);
        DateTime date = docProperties.Modified;

        // Check the year when the document was last modified,
        // and copy the file to the appropriate folder.
        switch (date.Year)
        {
            case 2017:
                string destFolder = @"D:\ExcelDocuments\2017";
                CheckDirectory(destFolder);
                file.CopyTo(Path.Combine(destFolder, file.Name), true);
                break;
            case 2018:
                destFolder = @"D:\ExcelDocuments\2018";
                CheckDirectory(destFolder);
                file.CopyTo(Path.Combine(destFolder, file.Name), true);
                break;
            case 2019:
                destFolder = @"D:\ExcelDocuments\2019";
                CheckDirectory(destFolder);
                file.CopyTo(Path.Combine(destFolder, file.Name), true);
                break;
            case 2020:
                destFolder = @"D:\ExcelDocuments\2020";
                CheckDirectory(destFolder);
                file.CopyTo(Path.Combine(destFolder, file.Name), true);
                break;
        }
    }
}

private static void CheckDirectory(string path)
{
    if (!Directory.Exists(path))
        Directory.CreateDirectory(path);
}
See Also