Current filter:
                                You should refresh the page.
                                  • I'm using the example E965  to store attachments in disk (vs. the database) in an XAF web app

                                    The solution wor ks well, however, I need to be able to check the file size and type and prevent upload/saving if this check fails.

                                    The standard ways of doing this with validation rules does not work as size is set later in the save process and I'm not sure how to access and modify the AspxUploaderControl.

                                1 Solution

                                Creation Date Importance Sort by

                                Hello Randy,
                                 
                                I used the https://search.devexpress.com/?q=web%20file%20size%20validation&f=70&m=SupportCenter search query and it returned some solutions that are still up-to-date today:
                                File Management > File Upload > Upload Modes
                                UploadControlValidationSettings > MaxFileSize
                                How to filter allowed file types for FileData properties in ASP.NET apps (an alternative to FileTypeFilterAttribute)
                                 
                                Please let me know how they work for you. Thanks.

                                See Also:
                                How to: Access the ASPxImagePropertyEditor controls in View and Edit modes - the same approach can be used for image property editors.

                                • Randy Jean 09.12.2019

                                  Thanks Dennis.  I decided to go the custom PropertyEditor route.  I can see that the properties are being set in debug, but the validation does not prevent the upload/save from occurring.

                                  I'm doing this in an editable listview. (see image attached)

                                  The AllowedFileExtensions is filtering the file dialog, so that's good.  However, it allows me to change to "All Types" and still upload a file type that is not in the filter.

                                  [C#]
                                  namespace MyApp.Module.Web.Editors { [PropertyEditor(typeof(FileSystemData.BusinessObjects.FileSystemStoreObject), false)] public class UltrasoundFileDataPropertyEditor : FileDataPropertyEditor { public UltrasoundFileDataPropertyEditor(Type objectType, IModelMemberViewItem info) : base(objectType, info) { } protected override void SetupControl(WebControl control) { base.SetupControl(control); if (ViewEditMode == ViewEditMode.Edit) { ASPxUploadControl aspxcontrol = ((FileDataEdit)control).UploadControl as ASPxUploadControl; aspxcontrol.ValidationSettings.ShowErrors = true; aspxcontrol.ValidationSettings.MaxFileSize = 1048576; aspxcontrol.ValidationSettings.MaxFileSizeErrorText = "Size of the uploaded file exceeds maximum file size of 1MB"; aspxcontrol.ValidationSettings.AllowedFileExtensions = new String[] { ".jpe", ".jpeg", ".jpg", ".gif", ".png", ".pdf", ".tif" }; aspxcontrol.ValidationSettings.NotAllowedFileExtensionErrorText = "Only jpg, gif, png, pdf or tif file types allowed."; } } } }
                                • Dennis (DevExpress) 09.12.2019

                                  Randy, would you please also enable 'Advanced' mode as described at Upload Modes? I am looking forward to hearing from you.

                                • Randy Jean 09.12.2019

                                  Works perfect now!  Thanks!

                                • Dennis (DevExpress) 09.12.2019

                                  Cool!