Skip to main content
A newer version of this page is available. .

FileTypeFilterAttribute Class

Applied to file data business classes, interfaces and their properties. Specifies a file type filter which appears in the Open dialog’s “Files of type” box.

Namespace: DevExpress.Persistent.Base

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

Declaration

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

Remarks

The File Attachments module supplies the File Property Editors. By default, these Property Editors are used for properties of the types that implement the DevExpress.Persistent.Base.IFileData interface. To load files, the FileDataPropertyEditor invokes the Open dialog. The FileTypeFilter attribute specifies a file type filter which will appear in the Open dialog’s “Files of type” box. It can be applied to a file data property whose type implements the IFileData interface or inherits from the DevExpress.Persistent.BaseImpl.FileAttachmentBase class. If the attribute is applied to a class of interface, then it has effect on a property whose name is passed to the FileAttachmentAttribute‘s FileAttachmentAttribute.FileDataPropertyName parameter.

The FileTypeFilter attribute has two constructors. The first constructor takes the filter description and a list of associated file extensions as the parameters. The second constructor has one more parameter, with which you can arrange the type filter strings in the required order, when multiple FileTypeFilter attributes are applied.

The file type filters defined via the FileTypeFilter attribute are reflected in the Application Model. For each file type filter defined by the FileTypeFilter attribute, a FileTypeFilters child node is added to the Application Model’s BOModel | <Class> | OwnMembers | <Member> node representing the target file data property. A FileTypeFilters child node comprises FileTypeFilter child nodes. Each FileTypeFilter child node represents a single file type filter. A FileTypeFilter, in turn, comprises Extension child nodes that define the extensions associated with a file type filter. You can define new and modify existing file type filters by editing the FileTypeFilters node via the Model Editor.

FileTypesFilter_ME

The following code snippet illustrates FileTypeFilter attribute use.

using DevExpress.Persistent.BaseImpl;

//...

public class CustomClass : BaseObject {
    private FileData document;

    public CustomClass(Session session) : base(session) { }

    [FileTypeFilter("Document files", 1, "*.txt", "*.doc")]
    [FileTypeFilter("Image files", 2, "*.bmp", "*.png", "*.gif", "*.jpg")]
    [FileTypeFilter("All files", 3, "*.*")]
    public FileData Document {
        get { return document; }
        set { SetPropertyValue("Document", ref document, value); }
    }
}

Tip

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

The following image shows the resulting Open dialog.

FileTypeFilterAttribute

For general information on the FileAttachments module, refer to the File Attachments Module Overview topic.

Note

Currently, the FileTypeFilterAttribute is supported in XAF Windows Forms applications only. So, it does not affect the Open dialogs invoked from XAF ASP.NET applications.

Inheritance

Object
Attribute
FileTypeFilterAttribute
See Also