New to Telerik UI for ASP.NET AJAX? Start a free 30-day trial

Provides a way to access individual files that have been uploaded by a client via a RadUpload control.

The UploadedFileCollection class provides access to all files uploaded from a client via single RadUpload instance as a file collection. UploadedFile provides properties and methods to get information on an individual file and to read and save the file. Files are uploaded in MIME multipart/form-data format and are NOT buffered in the server memory if the RadUploadModule is used.

The RadUpload control must be used to select and upload files from a client.

You can specify the maximum allowable upload file size in a machine.config or Web.config configuration file in the maxRequestLength attribute of the <httpRuntime> Element element.

Definition

Namespace:Telerik.Web.UI

Assembly:Telerik.Web.UI.dll

Syntax:

C#
public abstract class UploadedFile

Inheritance: objectUploadedFile

Derived Classes: AsyncPostedFile

Inherited Members object.ToString()object.Equals(object)object.Equals(object, object)object.ReferenceEquals(object, object)object.GetHashCode()object.GetType()object.MemberwiseClone()...

Example:

Set the maximum allowable upload file size to 1000kB

csharp
<httpRuntime maxRequestLength="1000" />
csharp
<httpRuntime maxRequestLength="1000" />

Constructors

C#
protected UploadedFile()

Properties

Gets the size in bytes of an uploaded file.

C#
public abstract long ContentLength { get; }
Property Value:

The length of the file.

Example:
cs-api-definition
bool isValid = true;
if (file.ContentLength &gt; MaxFileSize)
{
isValid = false;
}

Gets the MIME content type of a file sent by a client.

C#
public abstract string ContentType { get; }
Property Value:

The MIME content type of the uploaded file.

Example:
cs-api-definition
Dim Loop1 As Integer
Dim MyFileCollection As UploadedFileCollection = RadUpload1.UploadedFiles

For Loop1 = 0 To MyFileCollection.Count - 1
If MyFileCollection(Loop1).ContentType = "video/mpeg" Then
'...
End If
Next Loop1

Gets the fully-qualified name of the file on the client's computer (for example "C:\MyFiles\Test.txt").

C#
public abstract string FileName { get; }
Property Value:

A string containing the fully-qualified name of the file on the client's computer.

Example:
cs-api-definition
UploadedFile MyUploadedFile = RadUpload1.UploadedFiles[0];
string MyFileName = MyUploadedFile.FileName;
C#
protected abstract string InputFieldName { get; }

Gets a Stream object which points to the uploaded file to prepare for reading the contents of the file.

C#
public abstract Stream InputStream { get; }
Property Value:

A Stream pointing to the file.

Gets the last modified date of the uploaded file.

C#
public DateTime LastModifiedDate { get; }
Property Value:

Last modified date of the uploaded file.

The property is available only in RadAsyncUpload control when FileApi module is used

Methods

Creates a UploadedFile instance from HttpPostedFile instance.

C#
public static UploadedFile FromHttpPostedFile(HttpPostedFile file)
Parameters:fileHttpPostedFile

The HttpPostedFile instance. Usually, you could get this from a ASP:FileUpload control's PostedFile property

Returns:

UploadedFile

Creates a UploadedFile instance from HttpPostedFile instance.

C#
public static UploadedFile FromHttpPostedFile(string inputFieldName, HttpPostedFile file)
Parameters:inputFieldNamestring

The value of the name attribute of the file input field (equals the UniqueID of the FileUpload control)

fileHttpPostedFile

The HttpPostedFile instance. Usually, you could get this from a ASP:FileUpload control's PostedFile property

Returns:

UploadedFile

Returns the extension of the file on the client's computer.

C#
public string GetExtension()
Returns:

string

A string containing the extension of the file including the ".". If the file name does not have extension information, GetExtension returns string.Empty.

The extension of the file name is obtained by searching it for a period (.), starting with the last character and continuing toward the start. If a period is found before a DirectorySeparatorChar or AltDirectorySeparatorChar character, the returned string contains the period and the characters after it; otherwise, string.Empty is returned.

Returns the value of a custom field.

C#
public virtual string GetFieldValue(string fieldName)
Parameters:fieldNamestring

The name of the field which value will be retrieved

Returns:

string

A string containing the value of the custom field with name fieldName

Returns the checked state of a custom field.

C#
public bool GetIsFieldChecked(string fieldName)
Parameters:fieldNamestring

The name of the field which checked state will be retrieved

Returns:

bool

A string containing the checked state of the custom field with name fieldName

Returns the name and extension of the file on the client's computer.

C#
public string GetName()
Returns:

string

A string consisting of the characters after the last directory character in file name on the client's computer.

The separator characters used to determine the start of the file name are DirectorySeparatorChar and AltDirectorySeparatorChar.

Returns the name of the file on the client's computer without the extension.

C#
public string GetNameWithoutExtension()
Returns:

string

A string containing the name of the file on the client's computer without the extension.

A string containing the string returned by GetFileName, minus the last period (.) and all characters following it.

Saves the contents of an uploaded file.

C#
public abstract void SaveAs(string fileName, bool overwrite)
Parameters:fileNamestring

The name of the saved file.

overwritebool

true to allow an existing file to be overwritten; otherwise, false.

The maximum allowed uploaded file size is 4MB by default. Maximum file size can be specified in the machine.config or Web.config configuration files in the maxRequestLength attribute of the <httpRuntime> element.

The ASP.NET process must have proper rights for writing on the folder where the files are saved.

Example:
cs-api-definition
Dim Loop1 As Integer
Dim TempFileName As String
Dim ShouldOverwrite As Boolean = True
Dim MyFileCollection As UploadedFileCollection = RadUpload1.UploadedFiles

For Loop1 = 0 To MyFileCollection.Count - 1
' Create a new file name.
TempFileName = "C:\TempFiles\File_" &amp; CStr(Loop1)
' Save the file.
MyFileCollection(Loop1).SaveAs(TempFileName, ShouldOverwrite)
Next Loop1

Saves the contents of an uploaded file.

C#
public void SaveAs(string fileName)
Parameters:fileNamestring

The maximum allowed uploaded file size is 4MB by default. Maximum file size can be specified in the machine.config or Web.config configuration files in the maxRequestLength attribute of the <httpRuntime> element.

The ASP.NET process must have proper rights for writing on the folder where the files are saved.

Example:
cs-api-definition
Dim Loop1 As Integer
Dim TempFileName As String
Dim MyFileCollection As UploadedFileCollection = RadUpload1.UploadedFiles

For Loop1 = 0 To MyFileCollection.Count - 1
' Create a new file name.
TempFileName = "C:\TempFiles\File_" &amp; CStr(Loop1)
' Save the file.
MyFileCollection(Loop1).SaveAs(TempFileName)
Next Loop1