Skip to main content
.NET 6.0+

File Attachment Properties in XPO

  • 3 minutes to read

Properties of the IFileData type are named file attachment properties and use the File Attachment Property Editors. This topic describes the XPO-oriented ways to add a file attachment property in an persistent class. The following approaches are considered here:

Add a FileData Property Explicitly

In this section, the code snippet demonstrates an example of a FileData property to be added in your persistent class. Refer to the following topics for details on the attributes used in this example.

private FileData document;
[Aggregated, ExpandObjectMembers(ExpandObjectMembers.Never)]
[FileTypeFilter("DocumentFiles", 1, "*.txt", "*.doc")]
[FileTypeFilter("AllFiles", 2, "*.*")]
public FileData Document {
    get { return document; }
    set { SetPropertyValue(nameof(Document), ref document, value); }
}

Also, you can use the FileAttachmentAttribute to enable Actions that manage file attachments, in addition to the Property Editor functionality.

Add a FileData Property by Inheriting the FileAttachmentBase Class

The built-in abstract FileAttachmentBase class from the Business Class Library is decorated with the FileAttachmentAttribute and has the File property of the FileData type. To use the file attachment property, you can create a custom descendant of this class.

See an example of using this approach in the Attach Files to Objects topic.

Add XPCollection<FileAttachment> Type Properties

You can add a property of the XPCollection<FileAttachment> type where FileAttachment is a class that uses the FileAttachment attribute (e.g., the FileAttachmentBase class). In this instance, a List Property Editor with the FileAttachment object collection will be displayed in a UI. This Property Editor will be accompanied by the special Controller’s Actions:

  • WinForms applications

    The FileAttachmentController provides the Open and SaveTo Actions; and the FileAttachmentListViewController - the AddFromFile Action. Both these Controllers are activated only for Views with an object(s) that uses the FileAttachment attribute (List Views in the case of a FileAttachmentListViewController).

  • ASP.NET Web Forms applications

    The FileAttachmentController provides the Download Action. This Controller is activated only for Views with an object(s) that uses the FileAttachment attribute.

Note

To add file collections to a business class, you can implement the XPCollection<IFileData> type properties instead of the XPCollection<FileAttachment> type properties (FileAttachment is a class that uses the FileAttachment attribute). In this instance, these properties will be displayed by the List Property Editor as well. Note however, that the Actions listed above will not be displayed, because the special Controllers will not be activated.

Add a Custom File Attachment Property by Implementing the IFileData Interface

You can create your own IFileData implementation when required. To see an example, refer to the FileData class sources at %PROGRAMFILES%\DevExpress 23.2\Components\Sources\DevExpress.Persistent\DevExpress.Persistent.BaseImpl.EFCore\FileData.cs, or to the following articles: