Skip to main content
Tab

UploadControlValidationSettings.AllowedContentTypes Property

OBSOLETE

Use the AllowedFileExtensions property instead. Note, it accepts file extensions instead of content types.

Gets or sets the allowed content types of the uploaded file.

Namespace: DevExpress.Web

Assembly: DevExpress.Web.v24.1.dll

NuGet Package: DevExpress.Web

Declaration

[Obsolete("Use the AllowedFileExtensions property instead. Note, it accepts file extensions instead of content types.")]
public string[] AllowedContentTypes { get; set; }

Property Value

Type Description
String[]

An array of MIME content-type string values that contains the allowed content types.

Property Paths

You can access this nested property as listed below:

Library Object Type Path to AllowedContentTypes
ASP.NET Web Forms Controls ASPxUploadControl
.ValidationSettings .AllowedContentTypes
ASP.NET MVC Extensions UploadControlBinderSettings
.ValidationSettings .AllowedContentTypes
UploadControlSettings
.ValidationSettings .AllowedContentTypes

Remarks

Use the AllowedContentTypes property to allow end-users to only upload files with the specified content types. If the uploaded file’s content type is not allowed (it’s not listed by the AllowedContentTypes property), the ASPxUploadControl‘s validation fails and the UploadControlValidationSettings.NotAllowedContentTypeErrorText property’s value is displayed within the control’s specific error frame. If the ASPxUploadControl validation fails, the FileUploadCompleteEventArgs.IsValid, ASPxUploadControl.IsValid and ASPxClientUploadControlFileUploadCompleteEventArgs.isValid properties are set to false.

Note

Members of an array provided by the AllowedContentTypes property are standard MIME types. For a list of possible values, search for MIME in the Microsoft Documentation.

Note that setting just the AllowedContentTypes property is not sufficient to prevent any potentially harmful attack to a web site. Setting the UploadControlValidationSettings.AllowedFileExtensions property as well, is recommended.

See the Allowed File Extensions topic to learn more.

Example

<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));
    }
}
See Also