RadUpload for ASP.NET AJAX

RadControls for ASP.NET AJAX

RadUpload can automatically validate the size, file extension and mime-type of uploaded files against your preferences.

Caution

The selected files must be transferred to the server in order to be validated for size or mime-type. File extensions can be validated on the client using ASP.NET validators before the upload.

To enable integrated validation, you need only set the following RadUpload validation properties:

Size

Set the MaxFileSize property to enable file size validation. The value of this property specifies the maximum number of bytes allowed for each uploaded file.

Note

The default number of bytes you can transfer for all uploaded files is 4MB. If you want to allow uploads greater than 4 MB, you must configure the application for large uploads.

AllowedFileExtensions

The AllowedFileExtensions property lists the valid file extensions for uploaded files. When the AllowedFileExtensions property is set, RadUpload automatically validates the extensions of selected files, moving any files with disallowed extensions to the InvalidFiles collection.

Note

You must include the leading dot (".") in the file extension.

  • Click on the ellipsis button next to the AllowedFileExtensions property in the properties pane, and enter each extension on a separate line in the string collection editor.

  • In the ASP.NET source, list the extensions in a comma-delimited list:

    CopyASPX
    <telerik:radupload id="RadUpload1" runat="server" allowedfileextensions=".zip,.jpg,.jpeg" />
  •  

    In the code-behind, assign the value of the AllowedFileExtensions property to a string array:

AllowedMimeTypes

The AllowedMimeTypes property lists the valid MIME types for uploaded files. When the AllowedMimeTypes property is set, RadUpload automatically validates the MIME types of selected files, moving any files with disallowed extensions to the InvalidFiles collection.

Caution

There are several file extensions that have multiple MIME types associated with them. Different browsers send different MIME types for the same file. For these types of files, you need to set all associated MIME types for the file extension you want to allow.

You can set multiple mime-types the same way as setting multiple file extensions.

Validated files

Valid files can be accessed using the UploadedFiles property. Files that fail validation can be accessed using the InvalidFiles property.

After the validation, if you have specified a target folder, the valid files are automatically saved to the target folder.

The following example shows a RadUpload control configured to receive only ZIP files with size less than 1000000 bytes. It is configured to allow all mime-types associated with the .zip file extension. Valid files are automatically saved to the "~/My files" folder.

CopyASPX
<telerik:radupload id="RadUpload1" runat="server" allowedmimetypes="application/x-compressed,application/x-zip-compressed,application/zip,multipart/x-zip"
    maxfilesize="1000000" allowedfileextensions=".zip" targetfolder="~/My Files" />
<asp:Button runat="server" ID="Button1" Text="Submit" OnClick="Button1_Click" />

Processing Invalid files

The following example shows how to process invalid files. It provides feedback to the user about which files were rejected, and why:

 

See Also

Other Resources