ValidateUploadedFile() public static method

Uploaded file cannot be null. But if uploadedFile.HasFile is false, this will be a no-op. Pass null for acceptableFileExtensions if there is no restriction on file extension. PerformAdditionalImageValidation cannot be null but may be an empty delegate.
public static ValidateUploadedFile ( Validator validator, EwfFileUpload uploadedFile, string acceptableFileExtensions, System.Drawing.Image>.Action performAdditionalImageValidation, bool mustBeRenderableImage ) : void
validator Validator
uploadedFile EwfFileUpload
acceptableFileExtensions string
performAdditionalImageValidation System.Drawing.Image>.Action
mustBeRenderableImage bool
return void
Esempio n. 1
0
 private void validateFormValues(
     Validator validator, string subject, bool requireUploadIfNoFile, Action <Validator, System.Drawing.Image> validateImage, bool mustBeImage)
 {
     BlobFileOps.ValidateUploadedFile(validator, uploadedFile, acceptableFileExtensions, validateImage, mustBeImage);
     if (requireUploadIfNoFile && file == null && !uploadedFile.ValueChangedOnPostBack(AppRequestState.Instance.EwfPageRequestState.PostBackValues))
     {
         validator.NoteErrorAndAddMessage(Translation.PleaseUploadAFile + " '" + subject + "'.");
     }
 }
        private ControlList getUploadControlList()
        {
            var dm = PostBack.CreateFull(id: PostBack.GetCompositeId(postBackIdBase, "add"));

            RsFile file = null;
            var    fi   = FormItem.Create(
                "",
                new EwfFileUpload(),
                validationGetter: control => new EwfValidation(
                    (pbv, validator) => {
                BlobFileOps.ValidateUploadedFile(validator, control, acceptableFileExtensions, ValidateImage, AcceptOnlyImages);
                file = control.GetPostBackValue(pbv);
            },
                    dm));

            dm.AddModificationMethod(
                () => {
                if (file == null)
                {
                    return;
                }

                var existingFile = files.SingleOrDefault(i => i.FileName == file.FileName);
                int newFileId;
                if (existingFile != null)
                {
                    BlobFileOps.SystemProvider.UpdateFile(existingFile.FileId, file.FileName, file.Contents, BlobFileOps.GetContentTypeForPostedFile(file));
                    newFileId = existingFile.FileId;
                }
                else
                {
                    newFileId = BlobFileOps.SystemProvider.InsertFile(fileCollectionId, file.FileName, file.Contents, BlobFileOps.GetContentTypeForPostedFile(file));
                }

                if (NewFileNotificationMethod != null)
                {
                    NewFileNotificationMethod(newFileId);
                }
                EwfPage.AddStatusMessage(StatusMessageType.Info, "File uploaded successfully.");
            });

            return(ControlList.CreateWithControls(
                       true,
                       "Select and upload a new file:",
                       fi.ToControl(),
                       new PostBackButton(dm, new ButtonActionControlStyle("Upload new file"), false)));
        }