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

Telerik RadUpload

Definition

Namespace:Telerik.Web.UI

Assembly:Telerik.Web.UI.dll

Syntax:

C#
[TelerikToolboxCategory("Upload")]
[ToolboxBitmap(typeof(RadUpload), "Toolbox.Icons.Upload.png")]
[RequiredScript(typeof(Core))]
[RequiredScript(typeof(jQueryPlugins))]
[ClientScriptResource("Telerik.Web.UI.RadUpload", "Telerik.Web.UI.Upload.RadUpload.js")]
[EmbeddedSkin("Upload", typeof(RadUpload))]
[EmbeddedSkin("Upload", "Default", typeof(RadUpload))]
public class RadUpload : RadWebControl, IComponent, IDisposable, IParserAccessor, IUrlResolutionService, IDataBindingsAccessor, IControlBuilderAccessor, IControlDesignerAccessor, IExpressionsAccessor, IAttributeAccessor, IScriptControl, IControlResolver, IPostBackDataHandler, ISkinnableControl, IControl

Inheritance: objectControlWebControlRadWebControlRadUpload

Implements: IAttributeAccessorIComponentIControlIControlBuilderAccessorIControlDesignerAccessorIControlResolverIDataBindingsAccessorIDisposableIExpressionsAccessorIParserAccessorIPostBackDataHandlerIScriptControlISkinnableControlIUrlResolutionService...

Inherited Members WebControl.ApplyStyle(Style)WebControl.CopyBaseAttributes(WebControl)WebControl.CreateControlStyle()WebControl.LoadViewState(object)WebControl.TrackViewState()WebControl.MergeStyle(Style)WebControl.Render(HtmlTextWriter)WebControl.RenderBeginTag(HtmlTextWriter)WebControl.RenderEndTag(HtmlTextWriter)WebControl.SaveViewState()WebControl.AccessKeyWebControl.AttributesWebControl.BackColorWebControl.BorderColorWebControl.BorderWidthWebControl.BorderStyleWebControl.ControlStyleWebControl.ControlStyleCreatedWebControl.CssClassWebControl.DisabledCssClassWebControl.StyleWebControl.EnabledWebControl.EnableThemingWebControl.FontWebControl.ForeColorWebControl.HasAttributesWebControl.HeightWebControl.IsEnabledWebControl.SupportsDisabledAttributeWebControl.SkinIDWebControl.TabIndexWebControl.TagNameWebControl.ToolTipWebControl.WidthControl.ResolveAdapter()Control.HasEvents()Control.GetRouteUrl(object)Control.GetRouteUrl(string, object)Control.GetRouteUrl(RouteValueDictionary)Control.GetRouteUrl(string, RouteValueDictionary)Control.GetUniqueIDRelativeTo(Control)Control.ApplyStyleSheetSkin(Page)Control.OnDataBinding(EventArgs)Control.DataBind()Control.DataBind(bool)Control.DataBindChildren()Control.AddParsedSubObject(object)Control.EnsureID()Control.ClearChildState()Control.ClearChildControlState()Control.ClearChildViewState()Control.ClearEffectiveClientIDMode()Control.ClearCachedClientID()Control.Focus()Control.LoadControlState(object)Control.MapPathSecure(string)Control.OpenFile(string)Control.OnPreRender(EventArgs)Control.BuildProfileTree(string, bool)Control.SaveControlState()Control.RenderChildren(HtmlTextWriter)Control.RenderControl(HtmlTextWriter)Control.RenderControl(HtmlTextWriter, ControlAdapter)Control.OnUnload(EventArgs)Control.Dispose()Control.RaiseBubbleEvent(object, EventArgs)Control.OnBubbleEvent(object, EventArgs)Control.AddedControl(Control, int)Control.CreateControlCollection()Control.CreateChildControls()Control.ResolveUrl(string)Control.ResolveClientUrl(string)Control.FindControl(string)Control.FindControl(string, int)Control.GetDesignModeState()Control.HasControls()Control.IsLiteralContent()Control.EnsureChildControls()Control.RemovedControl(Control)Control.SetDesignModeState(IDictionary)Control.SetRenderMethodDelegate(RenderMethod)Control.ClientIDModeControl.ClientIDControl.ClientIDSeparatorControl.ContextControl.AdapterControl.DesignModeControl.EventsControl.IDControl.IsChildControlStateClearedControl.EnableViewStateControl.ViewStateModeControl.IsViewStateEnabledControl.NamingContainerControl.IdSeparatorControl.LoadViewStateByIDControl.PageControl.RenderingCompatibilityControl.TemplateControlControl.ParentControl.TemplateSourceDirectoryControl.AppRelativeTemplateSourceDirectoryControl.SiteControl.VisibleControl.UniqueIDControl.HasChildViewStateControl.ControlsControl.ValidateRequestModeControl.ViewStateControl.ViewStateIgnoresCaseControl.ChildControlsCreatedControl.IsTrackingViewStateControl.DisposedControl.DataBindingControl.InitControl.LoadControl.PreRenderControl.Unloadobject.ToString()object.Equals(object)object.Equals(object, object)object.ReferenceEquals(object, object)object.GetHashCode()object.GetType()object.MemberwiseClone()...

Constructors

C#
public RadUpload()

Properties

Gets or sets the allowed file extensions for uploading.

C#
[TypeConverter(typeof(ListConverter))]
[PersistenceMode(PersistenceMode.Attribute)]
[Bindable(true)]
public string[] AllowedFileExtensions { get; set; }
Property Value:

The default value is empty string array. In order to check for multiple file extensions you should set an array of strings containing the allowed file extensions for uploading.

Set this property to empty array of strings in order to prevent the file extension checking.

Note that the file extensions must include the dot before the actual extension. See the example below.

Example:
cs-api-definition
Dim allowedFileExtensions As String() = New String(2) {".zip", ".doc", ".config"}
RadUpload1.AllowedFileExtensions = allowedFileExtensions

Gets or sets the allowed MIME types for uploading.

C#
[TypeConverter(typeof(ListConverter))]
[PersistenceMode(PersistenceMode.Attribute)]
[Bindable(true)]
public string[] AllowedMimeTypes { get; set; }
Property Value:

The default value is empty string array. In order to check for multiple mime types you should set an array of strings containing the allowed MIME types for uploading.

Set this property to string.Empty in order to prevent the mime type checking.

Example:
cs-api-definition
' For example you can Get these from your web.config file
Dim commaSeparatedMimeTypes As String = "application/octet-stream,application/msword,video/mpeg"

Dim allowedMimeTypes As String() = commaSeparatedMimeTypes.Split(",")
RadUpload1.AllowedMimeTypes = allowedMimeTypes

Gets or sets the value indicating which control objects will be displayed.

C#
[Browsable(true)]
[Bindable(true)]
[ClientControlProperty]
public virtual ControlObjectsVisibility ControlObjectsVisibility { get; set; }
Property Value:

The default value is ControlObjectsVisibility.Default. You can set any combination of the enum values.

ControlObjectVisibility enum members

MemberDescription
NoneOnly the file inputs will be visible.
CheckBoxesDisplay checkboxes for selecting a file input.
RemoveButtonsDisplay buttons for removing a file input.
ClearButtonsDisplay buttons for clearing a file input.
AddButtonDisplay button for adding a file input.
DeleteSelectedButtonDisplay button for removing the file inputs with checked checkboxes.
DefaultCheckBoxes | RemoveButtons | AddButton | DeleteSelectedButton
AllCheckBoxes | RemoveButtons | ClearButtons | AddButton | DeleteSelectedButton
Example:
cs-api-definition
RadUpload1.ControlObjectsVisibility = Telerik.WebControls.ControlObjectsVisibility.AddButton Or _
Telerik.WebControls.ControlObjectsVisibility.RemoveButtons

The CssClass property will now be used instead of the former Skin and will be modified in AddAttributesToRender()

C#
protected override string CssClassFormatString { get; }

Overrides: RadWebControl.CssClassFormatString

Example:
C#
protected override string CssClassFormatString
{
       get
       {
           return "RadDock RadDock_{0} rdWTitle rdWFooter";
       }
}

Gets or sets the selected culture. Localization strings will be loaded based on this value.

C#
public CultureInfo Culture { get; set; }
Property Value:

The culture.

Gets or sets the value indicating whether the file input fields skinning will be enabled.

C#
[Browsable(true)]
[Bindable(true)]
[ClientPropertyName("enableFileInputSkinning")]
[ClientControlProperty]
public bool EnableFileInputSkinning { get; set; }
Property Value:

true when the file input skinning is enabled; otherwise false.

The <input type=file> DHTML elements are not skinnable by default. If the EnableFileInputSkinning is true some browsers can have strange behavior.

Gets or sets the value indicating whether the first file input field of RadUpload should get the focus on itself on load.

C#
[Browsable(true)]
[Bindable(true)]
[ClientPropertyName("focusOnLoad")]
[ClientControlProperty]
public bool FocusOnLoad { get; set; }
Property Value:

true when the first file input field of RadUpload should get the focus; otherwise false. The default value is false.

Gets or sets the initial count of file input fields, which will appear in RadUpload.

C#
[Browsable(true)]
[Bindable(true)]
[ClientPropertyName("initialFileInputsCount")]
[ClientControlProperty]
public int InitialFileInputsCount { get; set; }
Property Value:

The file inputs count which will be available at startup. The default value is 1.

Gets or sets the size of the file input field

C#
[PersistenceMode(PersistenceMode.Attribute)]
[Bindable(true)]
[ClientPropertyName("inputSize")]
[ClientControlProperty]
public int InputSize { get; set; }
Property Value:

The default value is 23.

Provides access to the invalid files uploaded by the RadUpload instance. This is populated only if a validation was set.

C#
[Browsable(false)]
public virtual UploadedFileCollection InvalidFiles { get; }
Property Value:

If the internal validation is enabled this collection contains the invalid uploaded files for the particular instance of RadUpload control.

Gets a value indicating whether the RadUpload HttpModule is registered in the current web.application

C#
[Browsable(false)]
public bool IsUploadModuleRegistered { get; }

Gets or sets the localization language of the RadUpload user interface.

C#
[Browsable(true)]
[Bindable(true)]
[Obsolete("Use the Culture property")]
public string Language { get; set; }
Property Value:

A string containing the localization language of the RadUpload user interface. The default value is en-US.

Gets the localization.

C#
[PersistenceMode(PersistenceMode.InnerProperty)]
public UploadStrings Localization { get; }
Property Value:

The localization.

Gets or sets a value indicating where RadUpload will look for its .resx localization files.

C#
public string LocalizationPath { get; set; }
Property Value:

The localization path.

Gets or sets the maximum file input fields that can be added to the control.

C#
[PersistenceMode(PersistenceMode.Attribute)]
[Bindable(true)]
[ClientPropertyName("maxFileCount")]
[ClientControlProperty]
public int MaxFileInputsCount { get; set; }
Property Value:

The default value is 0 (unlimited).

Using this property you can limit the maximum number of file inputs which can be added to a RadUpload instance.

Gets or sets the maximum file size allowed for uploading in bytes.

C#
[PersistenceMode(PersistenceMode.Attribute)]
[Bindable(true)]
public virtual int MaxFileSize { get; set; }
Property Value:

The default value is 0 (unlimited).

Set this property to 0 in order to prevent the file size checking.

Gets or sets the name of the client-side function which will be executed after a new file input is added to a RadUpload instance.

C#
[Browsable(true)]
[Bindable(true)]
[ClientControlEvent]
[ClientPropertyName("added")]
public string OnClientAdded { get; set; }
Property Value:

The default value is string.Empty.

Example:
cs-api-definition
&lt;radU:RadUpload OnClientAdded="myOnClientAdded" ... /&gt;
...
&lt;script&gt;
function myOnClientAdded()
{
alert("You just added a new file input.");
}
&lt;/script&gt;

Gets or sets the name of the client-side function which will be executed before a new file input is added to a RadUpload instance.

C#
[Browsable(true)]
[Bindable(true)]
[ClientControlEvent]
[ClientPropertyName("adding")]
public string OnClientAdding { get; set; }
Property Value:

The default value is string.Empty.

Example:
cs-api-definition
&lt;radU:RadUpload OnClientAdding="myOnClientAdding" ... /&gt;
...
&lt;script&gt;
function myOnClientAdding()
{
alert("You just added a new file input.");
}
&lt;/script&gt;

Gets or sets the name of the client-side function which will be executed before a file input field is cleared in a RadUpload instance using the Clear button.

C#
[Browsable(true)]
[Bindable(true)]
[ClientControlEvent]
[ClientPropertyName("clearing")]
public string OnClientClearing { get; set; }
Property Value:

The default value is string.Empty.

Example:
cs-api-definition
&lt;radU:RadUpload OnClientClearing="myOnClientClearing" ... /&gt;
...
&lt;script&gt;
function myOnClientClearing()
{
return confirm("Are you sure you want to clear this input?");
}
&lt;/script&gt;

Gets or sets the name of the client-side function which will be executed before a file input is deleted from a RadUpload instance.

C#
[Browsable(true)]
[Bindable(true)]
[ClientControlEvent]
[ClientPropertyName("deleting")]
public string OnClientDeleting { get; set; }
Property Value:

The default value is string.Empty.

If you want to cancel the deleting of the file input return false in the javascript handler.

Example:
cs-api-definition
&lt;radU:RadUpload OnClientDeleting="myOnClientDeleting" ... /&gt;
&lt;script language="javascript"&gt;
function myOnClientDeleting()
{
return prompt("Are you sure?");
}
&lt;/script&gt;

Gets or sets the name of the client-side function which will be executed before the selected file inputs are removed.

C#
[Browsable(true)]
[Bindable(true)]
[ClientControlEvent]
[ClientPropertyName("deletingSelected")]
public string OnClientDeletingSelected { get; set; }
Property Value:

The default value is string.Empty.

You can cancel the removing of the file input items by returning false in the javascript function.

Example:
cs-api-definition
&lt;radU:RadUpload OnClientDeletingSelected="myOnClientDeletingSelected" ... /&gt;

&lt;script&gt;
function myOnClientDeletingSelected()
{
var mustCancel = confirm("Are you sure?");
return mustCancel;
}
&lt;/script&gt;

Gets or sets the name of the client-side function which will be executed when a file input value changed.

C#
[Browsable(true)]
[Bindable(true)]
[ClientControlEvent]
[ClientPropertyName("fileSelected")]
public string OnClientFileSelected { get; set; }
Property Value:

The default value is string.Empty.

Gets or sets the value indicating whether RadUpload should overwrite existing files having same name in the TargetFolder.

C#
[Browsable(true)]
[Bindable(true)]
public bool OverwriteExistingFiles { get; set; }
Property Value:

true when the existing files should be overwritten; otherwise false. The default value is false.

When set to true, the existing files are overwritten, else no action is taken.

Gets or sets a value indicating if the file input fields should be read-only (e.g. no typing allowed).

C#
[Browsable(true)]
[Bindable(true)]
public bool ReadOnlyFileInputs { get; set; }
Property Value:

true when the file input fields should be read-only; otherwise false.

When users type into the box and the filename is not valid, the form submission in Internet Explorer could not proceed or even display a javascript error. This behavior can be avoided by setting the ReadOnlyFileInputs property to true.

C#
protected override HtmlTextWriterTag TagKey { get; }

Overrides: WebControl.TagKey

Gets or sets the virtual path of the folder, where RadUpload will automatically save the valid files after the upload completes.

C#
[Browsable(true)]
[Bindable(true)]
public string TargetFolder { get; set; }
Property Value:

A string containing the virtual path of the folder where RadUpload will automatically save the valid files after the upload completes. The default value is string.Empty.

When set to string.Empty, the files must be saved manually to the desired location.

If both TargetPhysicalFolder property and this property are set, the TargetPhysicalFolder will override the virtual path provided by TargetFolder.

Gets or sets the physical path of the folder, where RadUpload will automatically save the valid files after the upload completes.

C#
[Browsable(true)]
[Bindable(true)]
public string TargetPhysicalFolder { get; set; }
Property Value:

A string containing the physical path of the folder where RadUpload will automatically save the valid files after the upload completes. The default value is string.Empty.

When set to string.Empty, the files must be saved manually to the desired location.

If both TargetFolder property and this property are set, the TargetPhysicalFolder will override the virtual path provided by TargetFolder.

Provides access to the valid files uploaded by the RadUpload instance.

C#
[Browsable(false)]
public UploadedFileCollection UploadedFiles { get; }
Property Value:

UploadedFileCollection containing all valid files uploaded using a RadUpload control.

The collection contains only the files uploaded with the particular instance of the RadUpload control. If the RadUploadHttpModule is used, the uploaded files are removed from the Request.Files collection in order to conserve the server's memory. Else the Request.Files contains all uploaded files as a HttpPostedFile collection and each RadUpload instance has its own uploaded files as UploadedFileCollection.

Example:
cs-api-definition
For Each file As Telerik.WebControls.UploadedFile In RadUpload1.UploadedFiles
file.SaveAs(Path.Combine("c:\my files\", file.GetName()), True)
Next

Methods

C#
protected override void AddAttributesToRender(HtmlTextWriter writer)
Parameters:writerHtmlTextWriter

Overrides: RadWebControl.AddAttributesToRender(HtmlTextWriter)

C#
protected override void DescribeComponent(IScriptDescriptor descriptor)
Parameters:descriptorIScriptDescriptor

Overrides: RadWebControl.DescribeComponent(IScriptDescriptor)

C#
protected bool IsValidExtension(UploadedFile file)
Parameters:fileUploadedFileReturns:

bool

C#
protected bool IsValidMimeType(UploadedFile file)
Parameters:fileUploadedFileReturns:

bool

C#
protected bool IsValidSize(UploadedFile file)
Parameters:fileUploadedFileReturns:

bool

C#
protected bool IsValidUploadedFile(UploadedFile file, bool checkingFileSize, bool checkingFileExtension, bool checkingMimeType)
Parameters:fileUploadedFilecheckingFileSizeboolcheckingFileExtensionboolcheckingMimeTypeboolReturns:

bool

C#
protected bool IsValidUploadedFile(UploadedFile file)
Parameters:fileUploadedFileReturns:

bool

Executed when post data is loaded from the request

C#
protected override bool LoadPostData(string postDataKey, NameValueCollection postCollection)
Parameters:postDataKeystringpostCollectionNameValueCollectionReturns:

bool

Overrides: RadWebControl.LoadPostData(string, NameValueCollection)

Fires the FileExists event.

C#
protected virtual void OnFileExists(UploadedFileEventArgs e)
Parameters:eUploadedFileEventArgs
C#
protected override void OnInit(EventArgs e)
Parameters:eEventArgs

Overrides: RadWebControl.OnInit(EventArgs)

C#
protected override void OnLoad(EventArgs e)
Parameters:eEventArgs

Overrides: Control.OnLoad(EventArgs)

Fires the ValidatingFile event.

C#
protected virtual bool OnValidatingFile(ValidateFileEventArgs e)
Parameters:eValidateFileEventArgsReturns:

bool

C#
protected virtual void PopulateUploadedFiles()
C#
protected virtual void ProcessValidFiles()
C#
protected override void RenderContents(HtmlTextWriter writer)
Parameters:writerHtmlTextWriter

Overrides: RadWebControl.RenderContents(HtmlTextWriter)

C#
protected virtual void ValidateUploadedFiles()

Events

Occurs after an unsuccessful attempt for automatic saving of a file in the UploadedFiles collection.

C#
public event UploadedFileEventHandler FileExists

This event should be consumed only when the automatic file saving is enabled by setting the TargetFolder property. In this mode the files are saved in the selected folder with the same name as on the client computer. If a file with such name already exists in the TargetFolder it is either overwritten or skipped depending the value of the OverwriteExistingFiles property. This event is fired if OverwriteExistingFiles is set to false and a file with the same name already exists in the TargetFolder.

Example:
cs-api-definition
Private Sub RadUpload1_FileExists(ByVal sender As Object, ByVal e As WebControls.UploadedFileEventArgs) Handles RadUpload1.FileExists
Dim TheFile As Telerik.WebControls.UploadedFile = e.UploadedFile

TheFile.SaveAs(Path.Combine(RadUpload1.TargetFolder, TheFile.GetNameWithoutExtension() + "1" + TheFile.GetExtension()), true)
End Sub

Occurs before the internal validation of every file in the UploadedFiles collection.

C#
public event ValidateFileEventHandler ValidatingFile

To skip the internal validation of the file, set e.SkipInternalValidation = true.

Example:
cs-api-definition
Private Sub RadUpload1_ValidatingFile(ByVal sender As Object, ByVal e As WebControls.ValidateFileEventArgs) Handles RadUpload1.ValidatingFile
If e.UploadedFile.GetExtension.ToLower = ".zip" Then
Dim maxZipFileSize As Integer = 10000000 '~10MB
If e.UploadedFile.ContentLength &gt; maxZipFileSize Then
e.IsValid = False
End If
'The zip files are not validated for file size, extension and mime type
e.SkipInternalValidation = True
End If
End Sub