Skip to main content

File Attachments (Store Custom Files)

  • 6 minutes to read

The eXpressApp Framework supplies the File Attachments module and special file data types for file manipulation (upload, download, open, and save files). This module contains Property Editors and Controllers for the file data type.

Run Demo: File Attachment Properties ASP.NET Web Forms

Watch Video: XAF - Store file attachments in Dropbox instead of the database (XPO)

Supported Functionality



Attach a File
When a user clicks the ellipsis button on the FileDataPropertyEditor, the OpenFileDialog dialog is invoked to select a file that should be attached.
Save an Attached File to a Disk
The FileDataPropertyEditor context menu contains the SaveTo Action. The FileAttachmentController‘s SaveFileData method handles this Action’s Execute event. You can override this method in the FileAttachmentController descendant to change the default logic.
Open an Attached File
The FileDataPropertyEditor context menu contains the Open Action. The FileAttachmentController‘s Open method handles this Action’s Execute event. You can override this method in the FileAttachmentController descendant to change the default logic.
Detach a File
The FileDataPropertyEditor context menu contains the ClearContent Action. This Action’s Execute event handler calls the property type’s Clear method to clear the file content. Override the IFileData.Clear method to implement your logic.


File Attachment Properties Blazor

FileDataPropertyEditor displays the property’s value as a link with the file name. A user can click the link to download the file. In the Detail View, the Select File and Clear buttons are shown. FileAttachmentController contains corresponding Actions. A user should save changes after a file upload to display a link instead of a plain text file name.

FileDataPropertyEditor shows the upload progress while a file is uploading. The default maximum file size is 4 MB.

FileAttachmentsBlazorModule splits the file into chunks to upload to the server.

Web Forms

FileDataPropertyEditor displays the FileDataEdit control, which shows a different set of controls in View mode and Edit modes:

View Mode

Displays the HtmlAnchor control, which allows users to download the current file.


Edit Mode

FileDataPropertyEditor shows the Change File and Clear buttons, which are ASPxButtons.


The Clear button clears a property value. For this purpose, the property type’s Clear method is called. You can override the IFileData.Clear method to implement your logic.

The Change File button makes ASPxUploadControl visible to allow users to upload a new file.


A user can click the HtmlAnchor control with the file name to download the file.

The default maximum file size is 4 MB.

File Attachments Module Components

The following table contains classes for different platforms:


Module Class

WinForms (.NET 5 and .NET Framework)


ASP.NET Core Blazor


ASP.NET Web Forms


The File Attachments Module contains the following Property Editors to display file data properties in the UI:

  • DevExpress.ExpressApp.FileAttachment.Win.FileDataPropertyEditor
  • DevExpress.ExpressApp.FileAttachment.Blazor.FileDataPropertyEditor
  • DevExpress.ExpressApp.FileAttachment.Web.FileDataPropertyEditor

Add File Attachments Module to an XAF Application

Follow the steps below to add the File Attachments Module to your application. If you added this Module when you created an XAF application, the Solution Wizard generates the code below automatically.

  1. Add the corresponding NuGet package to the application project.



    NuGet Package







    Web Forms



  2. In the application constructor, add the File Attachments Module to the Modules collection:

    File: MySolution.Win\WinApplication.cs(.vb).

    using DevExpress.ExpressApp.FileAttachments.Win;
    // ...
    namespace MySolution.Win {
        public partial class MySolutionWinApplication : WinApplication {
            public MySolutionWinApplication() {
                // ...
                Modules.Add(new FileAttachmentsWindowsFormsModule());
            // ...

    File: MySolution.Blazor.Server\BlazorApplication.cs.

    using DevExpress.ExpressApp.FileAttachments.Blazor;
    // ...
    namespace MySolution.Blazor.Server {
        public partial class MySolutionBlazorApplication : BlazorApplication {
            public MySolutionBlazorApplication() {
                // ...
                Modules.Add(new FileAttachmentsBlazorModule());
            // ...

    Web Forms
    File: MySolution.Web\WebApplication.cs(.vb).

    using DevExpress.ExpressApp.FileAttachments.Web;
    // ...
    namespace MySolution.Web {
        public partial class MySolutionWebApplication : WebApplication {
            public MySolutionWebApplication() {
                // ...
                Modules.Add(new FileAttachmentsAspNetModule());
            // ...


Alternatively, you can use one of the following techniques to register the Module in your application:

For more information, see the following topic: Ways to Register a Module.

Define a File Data Object and Storage

The file data object is a business class that implements the IFileData interface. You can also use the built-in FileData class (XPO: the %PROGRAMFILES%\DevExpress 22.1\Components\Sources\DevExpress.Persistent\DevExpress.Persistent.BaseImpl\FileData.cs file, EFCore: the %PROGRAMFILES%\DevExpress 22.1\Components\Sources\DevExpress.Persistent\DevExpress.Persistent.BaseImpl.EF\FileData.cs file).

using DevExpress.Persistent.Base;
using DevExpress.Persistent.BaseImpl;

namespace MySolution.Module.BusinessObjects {
    public class MyFileAttachment : BaseObject {
        // ...
        private FileData file;
        public FileData File {
            get { return file; }
            set { SetPropertyValue(nameof(File), ref file, value); }
    public class FileData : BaseObject, IFileData {
    // ...

Refer to the following help topic for more information on file data properties: File Attachment Properties.

XAF stores attached files in the database in binary representation. When you use the DevExpress.Persistent.BaseImpl.FileData type, the gzip compression is applied to a file. The maximum file size is 2 GB.

Use the IFileData.LoadFromStream method to upload a file in code. To obtain the file, call the IFileData.SaveToStream method. The LoadFromStream method does not require a full path to the file. This method takes a file name as the first parameter.


View Example: How to: Store file attachments in the file system instead of the database View Example: How to: Store file attachments in Dropbox instead of the database


The following example implements a business class with a file data property and a file collection property: How to: Implement File Data Properties.

See Also