RadUpload for ASP.NET AJAX

RadControls for ASP.NET AJAX

If you need to perform additional actions on uploaded files before saving them (for example, if you are using custom fields), or if you want to manipulate them in memory without saving them, you can use the RadUpload server-side API. You can use the server-side API to rename uploaded files or save them into a database, or other storage medium.

Caution

If you set the TargetFolder or TargetPhysicalFolder property and then use the server-side API to manipulate the uploaded files, you may end up with two copies of the uploaded files. Be aware that any valid files will already be saved to the target folder.

RadUpload provides two properties to access the uploaded files:

  • UploadedFiles contains all valid uploaded files.

  • InvalidFiles contains uploaded files that did not pass the integrated validation or server-side custom validation. If you are not using either of these features, all uploaded files will appear in the UploadedFiles collection.

Both the UploadedFiles and InvalidFiles properties are of type Telerik.Web.UI.UploadedFileCollection. Each file in the collection is an instance of the UploadedFile class. The following table lists the members of the UploadedFile class:

 

Property or Method

Type (Return Type)

Description

Properties

ContentLength

integer

The size of the uploaded file, in bytes.

ContentType

string

The MIME type of the uploaded file.

FileName

string

The fully qualified name of the file on the client. (IE6 and some older browsers only). To get a file name that is the same for all browsers, use the GetName() method instead.

InputStream

System.IO.Stream

A stream object that can be used to read the file contents.

Methods

GetName()

string

Returns the name of the uploaded file.

GetNameWithoutExtension()

string

Returns the name of the uploaded file, without the file extension.

GetExtension()

string

Returns the extension of the uploaded file, including the leading dot (".")

SaveAs(string, [bool])

none

Save the file to the location specified by the first parameter. The optional second parameter specifies whether to overwrite an existing file if it is found.

GetFieldValue(string)

string

Retrieves a custom field added to the uploaded file.

GetIsFieldChecked(string)

boolean

Retrieves whether a custom check box added to the uploaded file was checked.

Saving uploaded files

The following example illustrates how to save uploaded files to a location of your choice:

CopyASPX
<telerik:radupload id="RadUpload1" runat="server" />
<asp:Button runat="server" ID="Button1" Text="Submit" OnClick="Button1_Click" />

 

Using the InputStream property

You can use the InputStream property to access the content of the uploaded files without saving them to a temporary location. This property is useful when you want to insert the file into a database, or process its contents without saving.

The following example demonstrates how to insert the uploaded files into a database using OleDb:

 

See Also