Skip to main content
.NET 8.0+

FileTypeFilterAttribute Class

Specifies a file type filter in the Open dialog’s “Files of type” box. You can apply this attribute to file data business classes, interfaces, and their properties in ASP.NET Core Blazor and Windows Forms applications.

Namespace: DevExpress.Persistent.Base

Assembly: DevExpress.Persistent.Base.v24.2.dll

Declaration

[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Interface, AllowMultiple = true, Inherited = false)]
public class FileTypeFilterAttribute :
    Attribute

Remarks

The File Attachments module supplies File Property Editors. XAF uses these Property Editors if the corresponding property type implements the DevExpress.Persistent.Base.IFileData interface. To load files, the FileDataPropertyEditor displays the Open dialog. The FileTypeFilter attribute specifies a file type filter that appears in the Open dialog’s “Files of type” box. You can apply this attribute to a file data property if its type implements the IFileData interface or inherits from the DevExpress.Persistent.BaseImpl.FileAttachmentBase class. If you apply the attribute to a class or interface, then it affects the property specified by the FileAttachmentAttribute.FileDataPropertyName attribute parameter.

The FileTypeFilter attribute has two constructors. One constructor accepts two parameters: a filter description and a list of associated file extensions. Another constructor requires an additional parameter that allows you to arrange type filter strings in the required order if you apply multiple FileTypeFilter attributes.

File type filters defined via the FileTypeFilter attribute are reflected by the Application Model. A FileTypeFilters child node appears in the BOModel | <Class> | OwnMembers | <Member> node that corresponds to the target file data property. A FileTypeFilters child node contains FileTypeFilter child nodes. Each FileTypeFilter child node represents a single file type filter, and a FileTypeFilter contains Extension child nodes that define file extensions. You can define new and modify existing file type filters by editing the FileTypeFilters node in the Model Editor.

FileTypesFilter_ME

The following code snippet demonstrates how to use the FileTypeFilter attribute:

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

public class CustomClass : BaseObject {
    [FileTypeFilter("Document files", 1, "*.txt", "*.doc")]
    [FileTypeFilter("Image files", 2, "*.bmp", "*.png", "*.gif", "*.jpg")]
    [FileTypeFilter("All files", 3, "*.*")]
    public virtual FileData Document { get; set; }
}

// Make sure that you use options.UseChangeTrackingProxies() in your DbContext settings.

Tip

If you have no access to the business class source to apply the attribute (for example, when you use a built-in FileAttachmentBase), use the Application Model instead.

The following image shows the resulting Open dialog:

ASP.NET Core Blazor
XAF ASP.NET Core Blazor FileTypeFilterAttribute, DevExpress
Windows Forms
XAF Windows Forms FileTypeFilterAttribute, DevExpress

Note

Currently, only XAF ASP.NET Core Blazor and Windows Forms applications support the FileTypeFilterAttribute.

ASP.NET Core Blazor functionality is limited by modern browser capabilities:

  1. All type filters are collected into a single filter list. For more information, refer to the following document: https://www.w3schools.com/TAGS/att_input_accept.asp.
  2. You cannot remove the “All Files (*.*)” option. You can only specify the DxUpload.AllowedFileExtensions property to verify file extensions on the client side.

For more information about the File Attachments module, refer to the following topic: File Attachments Module Overview.

Inheritance

Object
Attribute
FileTypeFilterAttribute
See Also