Skip to main content
.NET Framework 4.6.2+

FileAttachmentsWindowsFormsModule.CustomOpenFileWithDefaultProgram Event

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

Namespace: DevExpress.ExpressApp.FileAttachments.Win

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

Declaration

public event EventHandler<CustomFileOperationEventArgs> CustomOpenFileWithDefaultProgram

Event Data

The CustomOpenFileWithDefaultProgram event's data class is CustomFileOperationEventArgs. The following properties provide information specific to this event:

Property Description
FileData Specifies a file about to be opened via its associated program.
Handled Gets or sets a value that indicates whether the event handler has completely handled the event or whether the system should continue its own processing. Inherited from HandledEventArgs.

Remarks

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() {
        base.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;
        base.OnDeactivated();
    }        
}
See Also