All docs
V21.1
21.2 (EAP/Beta)
21.1
20.2
The page you are viewing does not exist in version 20.2. This link will take you to the root page.
20.1
The page you are viewing does not exist in version 20.1. This link will take you to the root page.
19.2
The page you are viewing does not exist in version 19.2. This link will take you to the root page.
19.1
The page you are viewing does not exist in version 19.1. This link will take you to the root page.
18.2
The page you are viewing does not exist in version 18.2. This link will take you to the root page.
18.1
The page you are viewing does not exist in version 18.1. This link will take you to the root page.
17.2
The page you are viewing does not exist in version 17.2. This link will take you to the root page.

How to: Use a Custom Action to Upload a File in a Popup Window

  • 2 minutes to read

The following example shows a popup window to upload a file and save it to a stream.

Popup Window to Upload a File

  1. Add the File Attachments Module to your application as described in the following section: Add File Attachments Module to an XAF Application

  2. Create the UploadFileParameters class with the File property of the FileData type. XAF shows FileDataPropertyEditor for this property type. For more information, see the following help topic: File Attachment Properties.

  3. Use an instance of the PopupWindowShowAction class to show a popup window.

  4. Handle the Execute event and call the SaveToStream(Stream) method to save the file to a stream. Note that the gzip compression is applied to the saved byte array.

using System.IO;
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Actions;
using DevExpress.ExpressApp.DC;
using DevExpress.Persistent.Base;
using DevExpress.Persistent.BaseImpl.EF; // For XPO, replace with 'using DevExpress.Persistent.BaseImpl;'.
using DevExpress.Persistent.Validation;

namespace XafUploadButton.Module.Controllers {
    public partial class UploadInPopupController : ViewController {
        public UploadInPopupController() {
            var customUploadFileAction = new PopupWindowShowAction(this,"CustomUploadFileAction", PredefinedCategory.View){
                Caption = "Custom Upload",
                ImageName = "AddFile"
            };
            customUploadFileAction.Execute += CustomUploadFileAction_Execute;
            customUploadFileAction.CustomizePopupWindowParams += CustomUploadFileAction_CustomizePopupWindowParams;
        }
        private void CustomUploadFileAction_Execute(object sender, PopupWindowShowActionExecuteEventArgs e) {
            FileData fileData = ((UploadFileParameters)e.PopupWindowViewCurrentObject).File;
            using(var stream = new MemoryStream()) {
                fileData.SaveToStream(stream);
                stream.Position = 0;
                // Perform your operations with the stream.
            }
        }
        private void CustomUploadFileAction_CustomizePopupWindowParams(object sender, CustomizePopupWindowParamsEventArgs e) {
            NonPersistentObjectSpace os = (NonPersistentObjectSpace)e.Application.CreateObjectSpace(typeof(UploadFileParameters));
            os.PopulateAdditionalObjectSpaces(Application);
            e.View = e.Application.CreateDetailView(os, os.CreateObject<UploadFileParameters>());
        }
    }
    [DomainComponent]
    public class UploadFileParameters : NonPersistentObjectImpl {
        private FileData file;
        [ExpandObjectMembers(ExpandObjectMembers.Never)]
        [RuleRequiredField("Save", "File should be assigned")]
        public FileData File {
            get { return file; }
            set { SetPropertyValue(ref file, value); }
        }
    }
}