Edit this page

Upload Validation

The RadUpload allows you to apply some limitations regarding the uploaded files thus validating the upload process.

In order to take advantage of this feature you will need to handle the RadUploadItem ValidateEvent event.

Add handler for the RadUploadItem ValidateEvent

Example 1: Subscribing to the Validate event

radUpload.AddHandler(RadUploadItem.ValidateEvent, new UploadValidateEventHandler(OnValidate));
    radUpload.AddHandler(RadUploadItem.ValidateEvent, New UploadValidateEventHandler(AddressOf OnValidate))

In order to add the ValidateEvent handler you need to include a using statement for the Telerik.Windows namespace.

Implement custom validation for the upload process

Example 2: Implementing custom validation

void OnValidate(object sender, UploadValidateEventArgs e)
{
    if ((e.OriginalSource as RadUploadItem).FileName.Equals("Desert.jpg"))
    {
        e.ErrorMessage = "Cannot upload this image!";
        e.Cancel = true;
    }
}
    Private Sub OnValidate(ByVal sender As Object, ByVal e As UploadValidateEventArgs)
        If (TryCast(e.OriginalSource, RadUploadItem)).FileName.Equals("Desert.jpg") Then
            e.ErrorMessage = "Cannot upload this image!"
            e.Cancel = True
        End If
    End Sub

If the selected file is named Desert.jpg, it won't be uploaded and the RadUpload will display a notification icon and a tooltip with the error message.