Back to Devexpress

ASPxUploadControl Class

aspnet-devexpress-dot-web-f36c888f.md

latest15.2 KB
Original Source

ASPxUploadControl Class

A file upload control.

Namespace : DevExpress.Web

Assembly : DevExpress.Web.v25.2.dll

NuGet Package : DevExpress.Web

Declaration

csharp
public class ASPxUploadControl :
    ASPxWebControl,
    IAssociatedControlID,
    ICallbackEventHandler
vb
Public Class ASPxUploadControl
    Inherits ASPxWebControl
    Implements IAssociatedControlID,
               ICallbackEventHandler

Remarks

The Upload Control can upload files with AJAX callbacks for improved responsiveness, offers built-in file validation support, and ships with an advanced client-side API.

Create an Upload Control

Design Time

The ASPxUploadControl control is available on the DX.25.2: Common Controls toolbox tab in the Microsoft Visual Studio IDE.

Drag the control onto a form and customize the control’s settings, or paste the control markup in the page’s source code.

aspx
<dx:ASPxUploadControl ID="ASPxUploadControl1" runat="server" UploadMode="Auto" 
     ShowProgressPanel="True" ShowUploadButton="True">
     <ValidationSettings AllowedFileExtensions=".jpg, .jpeg, .gif, .png" MaxFileSize="4194304" />
     <AdvancedModeSettings EnableDragAndDrop="True" EnableFileList="True" EnableMultiSelect="True" />
</dx:ASPxUploadControl>

Run Time

csharp
using DevExpress.Web;
...
protected void Page_Load(object sender, EventArgs e) {
     ASPxUploadControl uploadControl = new ASPxUploadControl();
     uploadControl.ID = "ASPxUploadControl1";
     uploadControl.UploadMode = UploadControlUploadMode.Auto;
     uploadControl.ShowProgressPanel = true;
     uploadControl.ShowUploadButton = true;
     uploadControl.AdvancedModeSettings.EnableDragAndDrop = true;
     uploadControl.AdvancedModeSettings.EnableFileList = true;
     uploadControl.AdvancedModeSettings.EnableMultiSelect = true;
     uploadControl.ValidationSettings.AllowedFileExtensions = new String[] { ".jpg", ".jpeg", ".gif", ".png" };
     uploadControl.ValidationSettings.MaxFileSize = 4194304;
     uploadControl.FileUploadMode = UploadControlFileUploadMode.OnPageLoad;
     // Add the created control to the page
     Page.Form.Controls.Add(uploadControl);
}
vb
Imports DevExpress.Web
...
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
    Dim uploadControl As ASPxUploadControl = New ASPxUploadControl()
    uploadControl.ID = "ASPxUploadControl1"
    uploadControl.UploadMode = UploadControlUploadMode.Auto
    uploadControl.ShowProgressPanel = True
    uploadControl.ShowUploadButton = True
    uploadControl.AdvancedModeSettings.EnableDragAndDrop = True
    uploadControl.AdvancedModeSettings.EnableFileList = True
    uploadControl.AdvancedModeSettings.EnableMultiSelect = True
    uploadControl.ValidationSettings.AllowedFileExtensions = New String() {".jpg", ".jpeg", ".gif", ".png"}
    uploadControl.ValidationSettings.MaxFileSize = 4194304
    uploadControl.FileUploadMode = UploadControlFileUploadMode.OnPageLoad
    ' Add the created control to the page
    Page.Form.Controls.Add(uploadControl)
End Sub

Important

DevExpress controls require that you register the ASPxUploadProgressHttpHandler and other special modules, handlers, and options, in the Web.config file. You can change this file or switch to the Design tab in the Microsoft Visual Studio IDE to automatically update the Web.config file. Note that this information is automatically registered if you use the DevExpress Template Gallery to create a project.

Client-Side API

The ASPxUploadControl‘s client-side API is implemented with JavaScript language and exposed by the ASPxClientUploadControl object.

|

Availability

|

Available by default.

| |

Client object type

|

ASPxClientUploadControl

| |

Access name

|

ASPxUploadControl.ClientInstanceName

| |

Events

|

ASPxUploadControl.ClientSideEvents

|

File Upload

The file upload starts when a user clicks the upload button or ASPxClientUploadControl.Upload method is called. Set the AutoStartUpload property to true to start file upload when a file is added to the upload control.

Upload EventDescription
ASPxUploadControl.FileUploadCompleteOccurs after a file has been uploaded to the server.
ASPxUploadControl.FilesUploadCompleteOccurs after all the selected files have been uploaded to the server.
ASPxClientUploadControl.FilesUploadStartOccurs on the client side before file upload is started.
ASPxClientUploadControl.FileUploadCompleteOccurs on the client side after a file has been uploaded.
aspx
<dx:ASPxUploadControl ID="ASPxUploadControl1" runat="server" OnFileUploadComplete="ASPxUploadControl1_FileUploadComplete">
     <ValidationSettings AllowedFileExtensions=".txt,.jpg,.jpe,.jpeg,.doc" MaxFileSize="1000000" />
</dx:ASPxUploadControl>
csharp
protected void ASPxUploadControl1_FileUploadComplete(object sender, DevExpress.Web.FileUploadCompleteEventArgs e) {
     if (e.IsValid) {
          e.UploadedFile.SaveAs(MapPath("Images/" + e.UploadedFile.FileName));
     }
}
vb
Protected Sub ASPxUploadControl1_FileUploadComplete(ByVal sender As Object, ByVal e As DevExpress.Web.FileUploadCompleteEventArgs)
    If e.IsValid Then
        e.UploadedFile.SaveAs(MapPath("Images/" & e.UploadedFile.FileName))
    End If
End Sub

Run Demo: Multi-File Selection

Multi-File Selection

To enable multi-file selection, set the AdvancedModeSettings.EnableMultiSelect property to true and the UploadMode property to Advanced.

aspx
<dx:ASPxUploadControl ID="UploadControl" UploadMode="Advanced" ...>
     <AdvancedModeSettings EnableMultiSelect="True" />
</dx:ASPxUploadControl>

Read Tutorial: Multi-File SelectionRun Demo: tMulti-File Selection

Integrated File Validation

With file validation, you can automatically validate file information on the server and provide descriptive error messages when necessary. The table below lists the validation properties.

|

Property

|

Description

|

Error Text Property

| | --- | --- | --- | |

AllowedFileExtensions

|

Gets or sets the allowed file extensions of the uploaded file.

|

NotAllowedFileExtensionErrorText

| |

MaxFileCount

|

Gets or sets the maximum file count to be uploaded at once.

|

MaxFileCountErrorText

| |

MaxFileSize

|

Specifies the maximum size of the uploaded file.

|

MaxFileSizeErrorText

|

aspx
<dx:ASPxUploadControl ID="UploadControl" UploadMode="Advanced" ... >
     <AdvancedModeSettings EnableMultiSelect="True" />
     <ValidationSettings MaxFileSize="4194304" MaxFileCount = "5" 
          AllowedFileExtensions=".jpg,.jpeg,.gif,.png" />
</dx:ASPxUploadControl>

Read Tutorial: Validation Run Demo: Multi-File Selection

Drag and Drop Support

End users can select multiple files and drag them to the Upload Control. To enable drag and drop functionality, set the AdvancedModeSettings.EnableDragAndDrop property to true and the UploadMode property to Advanced.

aspx
<dx:ASPxUploadControl ID="UploadControl" UploadMode="Advanced" ... >
     <AdvancedModeSettings EnableDragAndDrop="True" />
</dx:ASPxUploadControl>

You can specify external drop zones where users can drop files to add them to the upload control. List zone IDs in the AdvancedModeSettings.ExternalDropZoneID property.

Client EventDescription
DropZoneEnterFires when the mouse enters a drop zone while dragging a file.
DropZoneLeaveFires when the mouse leaves a drop zone while dragging a file.
aspx
<div id="externalDropZone" class="dropZoneExternal">
     <div id="dragZone">
            <span class="dragZoneText">Drag an image here</span>
     </div>
     
     <div id="dropZone" class="hidden">
          <span class="dropZoneText">Drop an image here</span>
     </div>
</div>
<dx:ASPxUploadControl ID="UploadControl" ClientInstanceName="UploadControl" runat="server" UploadMode="Auto" ... >
     <AdvancedModeSettings EnableDragAndDrop="True" ExternalDropZoneID="externalDropZone" DropZoneText="" />
     <ClientSideEvents> 
          DropZoneEnter="function(s, e) { if(e.dropZone.id == 'externalDropZone') setElementVisible('dropZone', true); }" 
          DropZoneLeave="function(s, e) { if(e.dropZone.id == 'externalDropZone') setElementVisible('dropZone', false); }" 
     </ClientSideEvents>
     ...
</dx:ASPxUploadControl>

Read Tutorial: Drag and Drop Run Demo: Drag and Drop Support

Cloud Storage Support

The ASPxUploadControl allows users to work with files stored on the most popular cloud services. Use the UploadStorage property to specify the cloud service where the control uploads files. The following cloud services are available:

|

|

|

Read Tutorial: Cloud Storage Account Management

UI Customization

The ASPxUploadControl ships with a rich set of customizable UI elements. Numerous settings and options allow you to fine-tune the upload control’s display and layout.

Read Tutorial: Upload Control Elements

Online Demos

Implements

Show 14 items

IComponent

IDisposable

IParserAccessor

IDataBindingsAccessor

IControlBuilderAccessor

IControlDesignerAccessor

IExpressionsAccessor

IAttributeAccessor

IUrlResolutionService

INamingContainer

IPostBackDataHandler

IPostBackEventHandler

IPropertiesOwner

ICallbackEventHandler

Inheritance

Object Control WebControl ASPxWebControlBase ASPxWebControl ASPxUploadControl ASPxHtmlEditorUploadControl

BootstrapUploadControl

MVCxUploadControl

See Also

ASPxUploadControl Members

DevExpress.Web Namespace