aspnet-devexpress-dot-web-dot-uploadcontrolvalidationsettings-16a82347.md
Specifies the maximum size of the uploaded file.
Namespace : DevExpress.Web
Assembly : DevExpress.Web.v25.2.dll
NuGet Package : DevExpress.Web
[DefaultValue(0L)]
public virtual long MaxFileSize { get; set; }
<DefaultValue(0L)>
Public Overridable Property MaxFileSize As Long
| Type | Default | Description |
|---|---|---|
| Int64 | 0 |
The maximum file size in bytes. 0, if the maximum size is not limited.
|
You can access this nested property as listed below:
| Library | Object Type | Path to MaxFileSize |
|---|---|---|
| ASP.NET MVC Extensions | UploadControlBinderSettings |
.ValidationSettings .MaxFileSize
| | UploadControlSettings |
.ValidationSettings .MaxFileSize
| | ASP.NET Web Forms Controls | ASPxUploadControl |
.ValidationSettings .MaxFileSize
|
Use the MaxFileSize property to limit the uploaded file size. If the uploaded file exceeds the property value, the ASPxUploadControl displays an error description. Use the MaxFileSizeErrorText property to customize the error text.
<dx:ASPxUploadControl ID="ASPxUploadControl1" runat="server" OnFileUploadComplete="uc_FileUploadComplete">
<ValidationSettings AllowedFileExtensions=".txt,.jpg,.jpe,.jpeg,.doc" MaxFileSize="1000000"
FileDoesNotExistErrorText="A file cannot be found."
GeneralErrorText="File uploading fails due to an external error that doesn't relate to the ASPxUploadControl's functionality."
MaxFileSizeErrorText="Uploaded file size exceeds the maximum file size."
NotAllowedFileExtensionErrorText="The file extension is not allowed.">
<ErrorStyle BackColor="Yellow" ForeColor="Black" />
</ValidationSettings>
</dx:ASPxUploadControl>
protected void uc_FileUploadComplete(object sender, DevExpress.Web.FileUploadCompleteEventArgs e) {
if (e.IsValid) {
ASPxUploadControl1.SaveAs(MapPath("Images/" + ASPxUploadControl1.FileName));
}
}
Protected Sub uc_FileUploadComplete(ByVal sender As Object, ByVal e As DevExpress.Web.FileUploadCompleteEventArgs)
If e.IsValid Then
ASPxUploadControl1.SaveAs(MapPath("Images/" & ASPxUploadControl1.FileName))
End If
End Sub
In the Standard Upload Mode, if the MaxFileSize property value exceeds the value of the Web.config’s MaxRequestLength setting, the following error occurs:
The ValidationSettings.MaxFileSize property’s value exceeds the Web.Config’s maxRequestLength setting. For the ASPxUploadControl’s built-in validation to work correctly, the ValidationSettings.MaxFileSize property should be less than the Web.config’s maxRequestLength setting.
To solve the issue, set the MaxFileSize value less than the MaxRequestLength value or use the Advanced Upload Mode.
See Also
UploadControlValidationSettings Class