Skip to main content
All docs
V25.1
  • Row

    Workbook.LoadDocumentProperties(String) Method

    Loads document properties from the specified workbook. The document format is determined automatically.

    You need a license for the DevExpress Office File API Subscription or DevExpress Universal Subscription to use this method in production code.

    Namespace: DevExpress.Spreadsheet

    Assembly: DevExpress.Docs.v25.1.dll

    NuGet Package: DevExpress.Document.Processor

    Declaration

    public ReadOnlyDocumentProperties LoadDocumentProperties(
        string fileName
    )

    Parameters

    Name Type Description
    fileName String

    The path to the target file.

    Returns

    Type Description
    ReadOnlyDocumentProperties

    An object that stores the retrieved document properties.

    Remarks

    Use this 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.

    The Spreadsheet Document API can load document properties from workbooks in the following formats:

    • XLSX,

    • XLSM,

    • XLSB,

    • XLS,

    • XLTX,

    • XLTM,

    • XLT,

    • XML (XML Spreadsheet 2003).

    For CSV and TXT files or encrypted documents, the LoadDocumentProperties method returns empty properties. If the loaded document is corrupted or its format is unknown, the LoadDocumentProperties method throws an exception.

    Example

    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