# Custom Validation

> caution  **RadUpload** has been replaced by [RadAsyncUpload](https://demos.telerik.com/aspnet-ajax/asyncupload/examples/overview/defaultcs.aspx), Telerik’s next-generation ASP.NET upload component. If you are considering Telerik’s Upload control for new development, check out the [documentation of RadAsyncUpload ](https://www.telerik.com/products/aspnet-ajax/documentation/controls/asyncupload/overview) or the [control’s product page](https://www.telerik.com/products/aspnet-ajax/asyncupload.aspx). If you are already using **RadUpload** in your projects, you may be interested in reading how easy the transition to RadAsyncUpload is and how you can benefit from it [in this article](https://www.telerik.com/products/aspnet-ajax/documentation/controls/asyncupload/migrating-from-radupload-for-asp.net-ajax-to-radasyncupload). The official support for **RadUpload** has been discontinued in June 2013 (Q2’13), although it is still be available in the suite. We deeply believe that **RadAsyncUpload** can better serve your upload needs and we kindly ask you to transition to it to make sure you take advantage of its support and the new features we constantly add to it.

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](https://www.telerik.com/products/aspnet-ajax/documentation/controls/upload/validation/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:

```ASPNET
<telerik:radupload id="RadUpload1" runat="server" maxfilesize="1000000" targetfolder="~/MyFiles"
    onvalidatingfile="RadUpload1_ValidatingFile"></telerik:radupload>
<asp:Button runat="server" ID="Button1" Text="Submit" />
```

```C#
	     	
using Telerik.Web.UI;
using Telerik.Web.UI.Upload;...
    
    private void RadUpload1_ValidatingFile( object sender, ValidateFileEventArgs e) 
    {  
        // check only the zip files  
        if (e.UploadedFile.GetExtension().ToLower() == ".zip")  
        {    
            //define the maximum file size to be 2000000 bytes    
            int maxZipFileSize = 2000000;    
            //if the zip file size exceeds 2000000 bytes mark it as invalid    
            if (e.UploadedFile.ContentLength > maxZipFileSize)    
            {       
                e.IsValid = false;
            }    
            // zip files must not be validated for file size by the internal validator    
            e.SkipInternalValidation = true;
        }
    }
				
```

```VB.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

        ' check only the zip files  
        If e.UploadedFile.GetExtension.ToLower = ".zip" Then
            'define the maximum file size to be 2000000 bytes    
            Dim maxZipFileSize As Integer = 2000000
            'if the zip file size exceeds 2000000 mark it as invalid
            If e.UploadedFile.ContentLength > maxZipFileSize Then
                e.IsValid = False
            End If
            'The zip files must not be validated for file size by the internal validator    
            e.SkipInternalValidation = True
        End If

    End Sub	
	
```

> note For an example of custom validation that checks the content of the uploaded file, see [ValidatingFile](https://www.telerik.com/products/aspnet-ajax/documentation/controls/upload/server-side-programming/validatingfile).

## See Also

* [Client-side Validation](https://www.telerik.com/products/aspnet-ajax/documentation/controls/upload/validation/client-side-validation)
