officefileapi-devexpress-dot-xtrarichedit-dot-richeditdocumentserverextensions-dot-loaddocumentproperties-x28-richeditdocumentserver-stream-documentformat-x29.md
Loads metadata (document properties) of a document in a specified format from the stream.
Namespace : DevExpress.XtraRichEdit
Assembly : DevExpress.Docs.v25.2.dll
NuGet Package : DevExpress.Document.Processor
public static ReadOnlyDocumentProperties LoadDocumentProperties(
this RichEditDocumentServer self,
Stream stream,
DocumentFormat documentFormat
)
<ExtensionAttribute>
Public Shared Function LoadDocumentProperties(
self As RichEditDocumentServer,
stream As Stream,
documentFormat As DocumentFormat
) As ReadOnlyDocumentProperties
| Name | Type | Description |
|---|---|---|
| self | RichEditDocumentServer |
The current RichEditDocumentServer instance.
| | stream | Stream |
A stream that stores a document which metadata should be loaded.
| | documentFormat | DocumentFormat |
The document format.
|
| Type | Description |
|---|---|
| ReadOnlyDocumentProperties |
A collection of document properties.
|
Important
The RichEditDocumentServerExtensions class is defined in the DevExpress.Docs.v25.2.dll assembly and DevExpress.Document.Processor NuGet package. Add this assembly or package to your project to use the RichEditDocumentServerExtensions members. You need a license for the DevExpress Office File API Subscription or DevExpress Universal Subscription to use this library in production code.
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 RichEditDocumentServer loads the document properties of the WordML and RTF files only if the metadata is before the document body.
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 25.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(File.OpenRead(filePath), DocumentFormat.Docx);
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;
}
}
Imports DevExpress.XtraRichEdit
Imports DevExpress.XtraRichEdit.API.Native
Imports System
Imports System.IO
Imports System.Diagnostics
Private Shared Sub Main(ByVal args As String())
Dim directoryInfo As DirectoryInfo = New DirectoryInfo("C:\Users\Public\Documents\DevExpress Demos 25.2\Components\Data")
Dim files As FileInfo() = directoryInfo.GetFiles("*.docx")
For Each file As FileInfo In files
SortDocuments(file.FullName, file.Name)
Next
Process.Start("explorer.exe", "C:\Documents")
End Sub
Public Shared Sub SortDocuments(ByVal filePath As String, ByVal fileName As String)
Dim wordProcessor As RichEditDocumentServer = New RichEditDocumentServer()
Dim docProperties As ReadOnlyDocumentProperties = wordProcessor.LoadDocumentProperties(File.OpenRead(filePath))
Dim date As DateTime = docProperties.BuiltIn.Modified
Select Case date.Year
Case 2017
File.Copy(filePath, String.Format("C://Documents//2017//{0}", fileName), True)
Case 2018
File.Copy(filePath, String.Format("C://Documents//2018//{0}", fileName), True)
Case 2019
File.Copy(filePath, String.Format("C://Documents//2019//{0}", fileName), True)
Case 2020
File.Copy(filePath, String.Format("C://Documents//2020//{0}", fileName), True)
End Select
End Sub
See Also
RichEditDocumentServerExtensions Class