Skip to main content
All docs
V24.1

How to: Load Document Properties for a Workbook

  • 2 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.v24.1.dll assembly. Add this assembly to your project to use the Workbook API. You need a license for the DevExpress Office File API Subscription or DevExpress Universal Subscription to use this assembly in production code.

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