Skip to main content
.NET 8.0+

DevExpress v25.1 Update — Your Feedback Matters

Our What's New in v25.1 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

IFileData Interface

Declares members that implement the base functionality of file data objects.

Namespace: DevExpress.Persistent.Base

Assembly: DevExpress.Persistent.Base.v25.1.dll

#Declaration

public interface IFileData

#Remarks

If your custom type implements the IFileData interface, XAF can display objects of this type in the File Data or PDF Viewer property editor.

Tip

Refer to the following file for a sample FileData class implementation: %PROGRAMFILES%\DevExpress 25.1\Components\Sources\DevExpress.Persistent\DevExpress.Persistent.BaseImpl.EFCore\FileData.cs

Display FileData.cs code
C#
using System;
using System.ComponentModel;
using System.IO;
using DevExpress.Persistent.Base;
using DevExpress.Persistent.Validation;

namespace DevExpress.Persistent.BaseImpl.EF {
    [DefaultProperty(nameof(FileName))]
    public class FileData : BaseObject, IFileData, IEmptyCheckable {
        private Byte[] content;
        public virtual Int32 Size { get; set; }
        public virtual String FileName { get; set; }
        public virtual Byte[] Content {
            get { return content; }
            set {
                if(content != value) {
                    content = value;
                    Size = content != null ? content.Length : 0;
                }
            }
        }
        [Browsable(false)]
        public Boolean IsEmpty {
            get { return String.IsNullOrEmpty(FileName); }
        }
        public void LoadFromStream(String fileName, Stream stream) {
            FileName = fileName;
            Byte[] bytes = new Byte[stream.Length];
            stream.Read(bytes, 0, bytes.Length);
            Content = bytes;
            ObjectSpace.SetModified(this);
        }
        public void SaveToStream(Stream stream) {
            if(String.IsNullOrEmpty(FileName)) {
                throw new InvalidOperationException();
            }
            stream.Write(Content, 0, Size);
            stream.Flush();
        }
        public void Clear() {
            Content = null;
            FileName = "";
            ObjectSpace.SetModified(this);
        }
        public override String ToString() {
            return FileName;
        }
    }
}

To access a full file path, additionally implement the ISupportFullName interface in your class.

File Data Property Editor (Blazor, WinForms, Web Forms)
Enable the File Attachments module to display objects that implement the IFileData interface in the File Data Property Editor.
PDF Viewer Property Editor (Blazor, WinForms)
Enable the Office Module and assign PdfViewerPropertyEditor to a file data property to display PDF files in the PDF Viewer.
Refer to the following topic for additional details: Use PDF Documents in Business Objects (CTP).
C#
using DevExpress.ExpressApp.Editors;
using DevExpress.Persistent.Base;
using DevExpress.Persistent.BaseImpl.EF;
// ...
public virtual FileData File { get; set; }
[EditorAlias(EditorAliases.PdfViewerPropertyEditor)]
public FileData ResumeView => File;

File Data and PDF Viewer Property Editors in an XAF Blazor Application

See Also