Edit this page

Create Custom RadUpload Control

If you need to create your own Upload control, you can rely on the RadUpload control to prepare your files for upload behind the scenes.

For example, if your application contains a custom control that creates a list of files for upload, you can create a RadUpload in code-behind to manage the files and upload them on the server.

In order to do so, you will need to manually add the list of the files into the CurrentSession.SelectedFiles collection:

Example 1: Selecting files

//create a RadUpload to handle the upload
RadUpload upload = new RadUpload;
// get a collection of files from the local system
List<FileInfo> files = new List<FileInfo>();
// add files 
// . . . 
// insert files in the RadUpload
if (files.Count > 0)
 foreach (FileInfo file in files)
  RadUploadSelectedFile f = new RadUploadSelectedFile(file);
//prepare for upload
    Dim upload As New RadUpload()
    ' get some files from the local system
    Dim files As New List(Of FileInfo)()
    ' add some files 
    ' . . . 
    ' insert files in the RadUpload
    If files.Count > 0 Then
     For Each file As FileInfo In files
    Dim f As New RadUploadSelectedFile(file)
    ' prepare for upload
    End If

The RadUploadSelectedFile class has a constructor that allows you to create a new instance from a Stream object: RadUploadSelectedFile f = new RadUploadSelectedFile(fileStream,fileName). However, in order to create a valid object of tyle RadUploadSelectedFile, you need to make sure that the fileStream Position is set to the beginning of the stream: fileStream.Position=0L. Only then you can use the Stream object to create a RadUploadSelectedFile instance.

Then you have to prepare the RadUpload control for the upload process. The PrepareSelectedFilesForUpload method facilitates the implementation of such scenarios by setting the RadUpload in a state ready to upload the manually added CurrentSession.SelectedFiles collection:

Example 2: Preparing for upload

// prepare for upload

Finally, you need to start the upload:

Example 3: Starting the upload

Was this article helpful? Yes No

Give article feedback

Tell us how we can improve this article