Create Custom Validaton Rule
If the built-in validation rule does not cover your requirements, you can create your custom validation rule. In order to do this you need to create a class deriving from the native ValidationRule and override its Validate() method. In that method you can implement custom logic validating the selected file. Since, you might have troubles with some cloud providers while uploading files containing underscores in their name, it might be reasonable to validate their name like this:
public class MyValidationRule:ValidationRule
{
public override ValidationResult Validate(object value, System.Globalization.CultureInfo cultureInfo)
{
var fileName = (string)value;
if (fileName.Contains(""))
{
return new ValidationResult(false, "You can not upload files containing underscore ('') in their name.");
}
return new ValidationResult(true, null);
}
}
Public Class MyValidationRule
Inherits ValidationRule
Public Overrides Function Validate(value As Object, cultureInfo As System.Globalization.CultureInfo) As ValidationResult
Dim fileName = DirectCast(value, String)
If fileName.Contains("") Then
Return New ValidationResult(False, "You can not upload files containing underscore ('') in their name.")
End If
Return New ValidationResult(True, Nothing)
End Function
End Class
Once this class is creted, you need to include it into the ValidationRules of the RadCloudUpload control. This can be done in XAML like this:
<telerik:RadCloudUpload>
<telerik:RadCloudUpload.ValidationRules>
<local:MyValidationRule />
</telerik:RadCloudUpload.ValidationRules>
...
</telerik:RadCloudUpload>