New to Telerik UI for ASP.NET AJAXStart a free 30-day trial

ValidatingFile

RadUpload has been replaced by RadAsyncUpload, 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 or the control’s product page. 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 blog post. 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.

The server-side ValidatingFile event occurs when files are uploaded, before any integrated file validation occurs:

The ValidatingFile event handler receives two arguments:

  1. The RadUpload control that initiated the file upload. This argument is of type object, but can be cast to the RadUpload type.

  2. A ValidatingFileEventArgs object. This object has the following properties:

    • UploadedFile is the file that has not yet been validated.

    • IsValid is a boolean you can set to indicate whether or not the file is valid.

    • SkipInternalValidation lets you disable the integrated file validation for this specific file.

Use the ValidatingFile event custom file validation. The following example uses the event to check that the content of the file matches the file name. If it does, the integrated file validation can proceed, if not, the file is considered invalid, and there is no need of further validation:

C#
	
protected void RadUpload1_ValidatingFile(object sender, Telerik.Web.UI.Upload.ValidateFileEventArgs e)
{
    UploadedFile file = e.UploadedFile;
    string name = file.GetNameWithoutExtension();
    byte[] bytes = new byte[name.Length];
    file.InputStream.Read(bytes, 0, name.Length);
    for (int i = 0; i < name.Length; i++)
    {
        if (bytes[i] != Convert.ToByte(name[i]))
        {
            e.IsValid = false;
            break;
        }
    }
    // if file is invalid, there is no need
    // to proceed with integrated validation
    e.SkipInternalValidation = !e.IsValid;
} 

See Also

In this article
See Also
Not finding the help you need?
Contact Support