File Attachment Properties in XPO

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.

[Aggregated, ExpandObjectMembers(ExpandObjectMembers.Never)]
[FileTypeFilter("DocumentFiles", 1, "*.txt", "*.doc")]
[FileTypeFilter("AllFiles", 2, "*.*")]
public FileData Document {
    get { return document; }
    set { SetPropertyValue("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 FileAttachmentsBase Class

The built-in abstract FileAttachmentsBase 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 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(x86)%\DevExpress 18.2\Components\Sources\DevExpress.Persistent\DevExpress.Persistent.BaseImpl\FileData.cs, or to the How to: Store file attachments in the file system instead of the database Support Center example.