RichEditDocumentServerExtensions.LoadDocumentProperties(RichEditDocumentServer, String) Method
Loads metadata (document properties) of a document from the specified file. The document format is determined automatically.
Namespace: DevExpress.XtraRichEdit
Assembly: DevExpress.Docs.v24.2.dll
NuGet Package: DevExpress.Document.Processor
#Declaration
public static ReadOnlyDocumentProperties LoadDocumentProperties(
this RichEditDocumentServer self,
string fileName
)
#Parameters
Name | Type | Description |
---|---|---|
self | Rich |
The current Rich |
file |
String | A path to the document which metadata should be loaded. |
#Returns
Type | Description |
---|---|
Read |
A collection of document properties. |
#Remarks
Important
The Rich
Use this method to load document properties without loading the document itself. Refer to the following help topic for a list of supported document properties in different formats: How to: Specify Document Properties.
Note
The Rich
The code sample below loads the document properties and sorts files by their modification date:
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 24.2\Components\Data");
FileInfo[] files = directoryInfo.GetFiles("*.docx");
if (directoryInfo.Exists)
{
foreach (FileInfo file in files)
{
SortDocuments(file);
}
Process.Start("explorer.exe", @"C:\Documents");
}
}
static void SortDocuments(FileInfo file)
{
using (RichEditDocumentServer wordProcessor = new RichEditDocumentServer())
{
//Load the metadata from the specified document:
ReadOnlyDocumentProperties docProperties =
wordProcessor.LoadDocumentProperties(File.OpenRead(file.FullName));
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:
string destFolder = "C://Documents//2017";
CreateDirectory(destFolder);
file.CopyTo(Path.Combine(destFolder, file.Name), true);
break;
case 2018:
destFolder = "C://Documents//2018";
CreateDirectory(destFolder);
file.CopyTo(Path.Combine(destFolder, file.Name), true);
break;
case 2019:
destFolder = "C://Documents//2019";
CreateDirectory(destFolder);
file.CopyTo(Path.Combine(destFolder, file.Name), true);
break;
case 2020:
destFolder = "C://Documents//2020";
CreateDirectory(destFolder);
file.CopyTo(Path.Combine(destFolder, file.Name), true);
break;
}
}
}
static void CreateDirectory(string path)
{
if (!Directory.Exists(path))
Directory.CreateDirectory(path);
}