Skip to main content

UploadControlExtension.GetUploadedFiles(String, UploadControlValidationSettings, out String[], EventHandler<FileUploadCompleteEventArgs>, EventHandler<FilesUploadCompleteEventArgs>) Method

Returns an array of the files uploaded via the specified UploadControl, and accepts specific parameters.

Namespace: DevExpress.Web.Mvc

Assembly: DevExpress.Web.Mvc5.v23.2.dll

NuGet Package: DevExpress.Web.Mvc5

Declaration

public static UploadedFile[] GetUploadedFiles(
    string name,
    UploadControlValidationSettings validationSettings,
    out string[] errorTexts,
    EventHandler<FileUploadCompleteEventArgs> fileUploadCompleteDelegate,
    EventHandler<FilesUploadCompleteEventArgs> filesUploadCompleteDelegate
)

Parameters

Name Type Description
name String

A string value specifying the UploadControl’s name (SettingsBase.Name).

validationSettings UploadControlValidationSettings

A UploadControlValidationSettings object that contains settings that relate to the uploaded file validation.

errorTexts String[]

An array of strings specifying error explanation texts specific to the uploaded files.

fileUploadCompleteDelegate EventHandler<FileUploadCompleteEventArgs>

A delegate method that implements custom validation of an uploaded file.

filesUploadCompleteDelegate EventHandler<FilesUploadCompleteEventArgs>

A delegate method that implements custom validation of all uploaded files.

Returns

Type Description
UploadedFile[]

An array of UploadedFile objects associated with file input elements.

Remarks

View Example: Upload Control for ASP.NET MVC - How to upload multiple files simultaneously

@using (Html.BeginForm("UploadControlUpload", "Home")) {
    @Html.DevExpress().UploadControl(settings => {
    settings.Name = "UploadControl";
    settings.ShowUploadButton = true;
    settings.ShowProgressPanel = true;
    settings.AdvancedModeSettings.EnableMultiSelect = true;
    settings.AdvancedModeSettings.EnableFileList = true;
    settings.AdvancedModeSettings.EnableDragAndDrop = true;
    settings.UploadMode = DevExpress.Web.UploadControlUploadMode.Advanced;
    settings.ValidationSettings.Assign(MyUploadControlValidationSettings.Settings);
    settings.ClientSideEvents.FilesUploadComplete = "OnFilesUploadComplete";
}).GetHtml()
}
public ActionResult UploadControlUpload() {
    string[] errors;

    UploadedFile[] files = UploadControlExtension.GetUploadedFiles("UploadControl",
        MyUploadControlValidationSettings.Settings, out errors, (s, e) => { },
        UploadControl_FilesUploadComplete);

    return null;
}
public void UploadControl_FilesUploadComplete(object sender, FilesUploadCompleteEventArgs e) {
    UploadedFile[] files = ((MVCxUploadControl)sender).UploadedFiles;

    for (int i = 0; i < files.Length; i++) {
        if (files[i].IsValid && !string.IsNullOrWhiteSpace(files[i].FileName)) {
            string resultFilePath = "~/Content/" + files[i].FileName;
            files[i].SaveAs(System.Web.HttpContext.Current.Request.MapPath(resultFilePath)); 

            string file = string.Format("{0} ({1}KB)", files[i].FileName, files[i].ContentLength / 1024);
            string url = ((IUrlResolutionService)sender).ResolveClientUrl(resultFilePath);

            e.CallbackData += file + "|" + url + "|";
        }
    }
}
public class MyUploadControlValidationSettings {
    public static UploadControlValidationSettings Settings = new UploadControlValidationSettings() {
        AllowedFileExtensions = new string[] { ".jpg", ".jpeg", ".png", ".bmp", ".pdf", ".xml", ".txt", ".rtf", ".docx", ".xls", ".xlsx" },
        MaxFileSize = 4194304
    };
}

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the GetUploadedFiles(String, UploadControlValidationSettings, out String[], EventHandler<FileUploadCompleteEventArgs>, EventHandler<FilesUploadCompleteEventArgs>) method.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also