RadControls for ASP.NET AJAX
In addition to the integrated validation, RadUpload lets you
perform your own custom validation using the server-side
ValidatingFile event. By using this event, you can use your own
custom validation logic and override the integrated validation if needed.
To validate a file in the ValidatingFile event handler, set the
IsValid property of the event arguments to true or
false, in order to indicate whether the file is valid. Then set the
SkipInternalValidation property of the event arguments to true to bypass
the default validation on any files you have validated using the event handler.
As with integrated validation,
valid files can be accessed using the UploadedFiles property and invalid
files using the InvalidFiles property.
The following example illustrates using custom validation to bypass the integrated size validation
for zip files. The rest of the uploaded files are validated against the declared maximum file size:
CopyASPX
<telerik:radupload id="RadUpload1" runat="server" maxfilesize="1000000" targetfolder="~/MyFiles"
onvalidatingfile="RadUpload1_ValidatingFile"></telerik:radupload>
<asp:Button runat="server" ID="Button1" Text="Submit" />
CopyC#
using Telerik.Web.UI;
using Telerik.Web.UI.Upload;...
private void RadUpload1_ValidatingFile( object sender, ValidateFileEventArgs e)
{
if (e.UploadedFile.GetExtension().ToLower() == ".zip")
{
int maxZipFileSize = 2000000;
if (e.UploadedFile.ContentLength > maxZipFileSize)
{
e.IsValid = false;
}
e.SkipInternalValidation = true;
}
}
CopyVB.NET
Imports Telerik.Web.UI
Imports Telerik.Web.UI.Upload...
Private Sub RadUpload1_ValidatingFile(ByVal sender As Object, ByVal e As ValidateFileEventArgs) Handles RadUpload1.ValidatingFile
If e.UploadedFile.GetExtension.ToLower = ".zip" Then
Dim maxZipFileSize As Integer = 2000000
If e.UploadedFile.ContentLength > maxZipFileSize Then
e.IsValid = False
End If
e.SkipInternalValidation = True
End If
End Sub Note |
|---|
For an example of custom validation that checks the content of the uploaded file, see
ValidatingFile.
|
See Also