Edit this page

Working with RadUpload

This topic will explain in details how to work with the RadUpload.

Defining a RadUpload control

Here is a sample declaration of a RadUpload control.

The RadUpload control is located in the Telerik.Windows.Controls namespace of the Telerik.Windows.Controls.Input assembly.

Example 1: Defining RadUpload in XAML

<telerik:RadUpload />

Example 2: Defining RadUpload in code

RadUpload radUpload = new RadUpload();
Dim radUpload As New RadUpload()

Defining an Upload Service

The first thing you have to do is to add a reference to the Telerik.Windows.RadUploadHandler assembly in the ASP.NET application, that hosts your Silverlight application. After that create a Generic (ASHX) Handler, that derives from the RadUploadHandler class.

Example 3: Defining upload handler

public class SampleUploadHandler : RadUploadHandler
{
}
Public Class SampleUploadHandler
 Inherits RadUploadHandler
End Class

Create a folder, in which the uploaded files will get stored.

Please, note the target folder should be in the same folder as the upload handler.

To test the handler point your browser to the SampleUploadHandler.ashx file. You should see the following output if everything is done correctly.

To learn how to create custom upload handlers read this topic.

Specifying an Upload Service

To specify an Upload Service for the RadUpload control you have to set the url of the service to the UploadServiceUrl of the RadUpload. The value should be an absolute or relative url that points to the upload handler.

The domain where the Silverlight application is hosted should be the same as the domain where the upload handler is hosted, otherwise a cross-domain conflict will occur. In such case you have to add a Cross-Domain Policy file to the services domain.

For example, if you rely on the absolute path, the UploadServiceUrl should point to http://localhost:6519/SampleUploadHandler.ashx and the Silverlight application should be hosted on the same domain - for example on this url: http://localhost:6519/index.html. Note that the port of the application should be the same (in this case the port is set to 6519, but any other port - including the default port 80 - will work).

If you prefer the relative path then pay attention to the following things:

  • if the path begins with "/" or "~/" then it is relative to the root of the domain where the Silverlight application had been loaded.

  • if the path begins with "./" then it is relative to the location of the Silverlight application.

  • if the path begins with one or more "../", then it is relative to the location above the location of the Silverlight application.

Example 4: Setting the upload service URI

<telerik:RadUpload UploadServiceUrl="/SampleUploadHandler.ashx" />

Specifying the Upload Folder

To specify the folder to which the files to be uploaded, you have to set one of the following properties:

  • TargetFolder - use this property, if the storage folder is relative to the upload handler.

    Example 5: Setting the upload target folder

        <telerik:RadUpload UploadServiceUrl="/SampleUploadHandler.ashx"
                           TargetFolder="UserUploads" />
    
  • TargetPhysicalFolder - use this property with the full path of the storage folder.

    Example 6: Setting the upload target folder

        <telerik:RadUpload UploadServiceUrl="/SampleUploadHandler.ashx"
                           TargetPhysicalFolder="C:\RadUploadSample\RadUploadSample.Web\UserUploads" />
    

    If both TargetPhysicalFolder and TargetFolder are set, the TargetPhysicalFolder will take precedence.

Restricting the User from Certain Actions

You can use the following properties to restrict the user actions against the RadUpload control:

  • IsDeleteEnabled - when set to False the user is not able to remove files from the selected file list. The default value is True.

  • IsPauseEnabled - when set to False the user is not able to pause the upload process. The default value is True.

See Also

Was this article helpful? Yes No

Give article feedback

Tell us how we can improve this article

Dummy