Back to Devexpress

UploadControlValidationSettings.MaxFileSize Property

aspnet-devexpress-dot-web-dot-uploadcontrolvalidationsettings-16a82347.md

latest4.6 KB
Original Source

UploadControlValidationSettings.MaxFileSize Property

Specifies the maximum size of the uploaded file.

Namespace : DevExpress.Web

Assembly : DevExpress.Web.v25.2.dll

NuGet Package : DevExpress.Web

Declaration

csharp
[DefaultValue(0L)]
public virtual long MaxFileSize { get; set; }
vb
<DefaultValue(0L)>
Public Overridable Property MaxFileSize As Long

Property Value

TypeDefaultDescription
Int640

The maximum file size in bytes. 0, if the maximum size is not limited.

|

Property Paths

You can access this nested property as listed below:

LibraryObject TypePath to MaxFileSize
ASP.NET MVC ExtensionsUploadControlBinderSettings

.ValidationSettings .MaxFileSize

| | UploadControlSettings |

.ValidationSettings .MaxFileSize

| | ASP.NET Web Forms Controls | ASPxUploadControl |

.ValidationSettings .MaxFileSize

|

Remarks

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.

aspx
<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>
csharp
protected void uc_FileUploadComplete(object sender, DevExpress.Web.FileUploadCompleteEventArgs e) {
    if (e.IsValid) {
        ASPxUploadControl1.SaveAs(MapPath("Images/" + ASPxUploadControl1.FileName));
    }
}
vb
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

Exception

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

UploadControlValidationSettings Members

DevExpress.Web Namespace