Edit this page

OnFileUploaded

The server-side FileUploaded occurs after a file is uploaded and a postback is triggered.

note

When the PostbackTriggers property of the RadAsyncUpload is set to a particular button, the FileUploaded event will fire only when that button is clicked.

The FileUploaded event handler receives two arguments:

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

  • An FileUploadedEventArgs object that has three properties:

  • IsValid - Allows you to specify whether the uploaded file is valid. If it is, RadAsyncUpload will automatically save it to the TargetFolder, if one is set.

  • File - Provides reference to the file uploaded.

  • UploadResult - A container object containing information sent from the RadAsyncUpload file handler. For additional information, visit How to extend the RadAsyncUpload handler.

The example below demonstrates how to prepare the previously uploaded file to send as an e-mail attachment:

void RadAsyncUpload1_FileUploaded(object sender, FileUploadedEventArgs e)
{
    e.IsValid = !CheckUploadedFileValidity();
    if (e.IsValid)
    {
        byte[] buffer = new byte[e.File.ContentLength];
        using (Stream str = e.File.InputStream)
        {
            str.Read(buffer, 0, buffer.Length);
            var attachment = createAttachment(buffer);
            // more code
        }
    }
}   
Private Sub RadAsyncUpload1_FileUploaded(ByVal sender As Object, ByVal e As FileUploadedEventArgs)
    e.IsValid = Not CheckUploadedFileValidity()
    If e.IsValid Then
        Dim buffer As Byte() = New Byte(e.File.ContentLength - 1) {}
        Using str As Stream = e.File.InputStream
            str.Read(buffer, 0, buffer.Length)
            ' more code
            Dim attachment = createAttachment(buffer)
        End Using
    End If
End Sub

See Also

Getting Started

How to extend the RadAsyncUpload handler

Server-Side Events