FileAttachmentsWindowsFormsModule.CustomOpenFileWithDefaultProgram Event

Occurs prior to opening an attached file via its associated program.

Namespace: DevExpress.ExpressApp.FileAttachments.Win

Assembly: DevExpress.ExpressApp.FileAttachment.Win.v18.2.dll


public event EventHandler<CustomFileOperationEventArgs> CustomOpenFileWithDefaultProgram
Public Event CustomOpenFileWithDefaultProgram As EventHandler(Of CustomFileOperationEventArgs)

The event handler receives an argument of the CustomFileOperationEventArgs type.

Property Description

Specifies a file about to be opened via its associated program.

When the FileAttachmentController's Open Action is executed, a selected file is saved to the operating system's temporary folder, and then passed to the operating system, to be opened. The operating system then searches for an associated program and opens the file. The FileAttachmentsWindowsFormsModule does not delete the saved file, because it cannot determine when the file is no longer used. So, the end-user needs to periodically clean the temporary folder's content. You can override this behavior by handling the CustomOpenFileWithDefaultProgram event. After opening an attached file using the associated program and performing necessary cleanup, set the handler's Handled parameter to true, to cancel the default file opening routine.

using DevExpress.ExpressApp;
using DevExpress.ExpressApp.FileAttachments.Win;
using DevExpress.Persistent.Base;
public class MyViewController : ViewController {
    FileAttachmentsWindowsFormsModule fileAttachmentsModule;
    protected override void OnActivated() {
        fileAttachmentsModule = Application.Modules.FindModule<FileAttachmentsWindowsFormsModule>();
        fileAttachmentsModule.CustomOpenFileWithDefaultProgram += OnCustomOpenFile;
    void OnCustomOpenFile(object sender, CustomFileOperationEventArgs e) {
        //manually open the e.FileData file and perform necessary cleanup
        e.Handled = true;
    protected override void OnDeactivated() {
        fileAttachmentsModule.CustomOpenFileWithDefaultProgram -= OnCustomOpenFile;
        fileAttachmentsModule = null;

See Also