ASPxUploadControl.UploadedFiles Property
Provides access to an array whose entries correspond to the ASPxUploadControl’s file input elements and contain information on the uploaded files, if any.
Namespace: DevExpress.Web
Assembly:
DevExpress.Web.v24.2.dll
Declaration
public UploadedFile[] UploadedFiles { get; }
Public ReadOnly Property UploadedFiles As UploadedFile()
Property Value
In order to upload a file, an end-user should specify it within a file input element. The total amount of available file input elements is controlled via the ASPxUploadControl.FileInputCount property. This amount can also be dynamically changed by end-users on the client, if the ASPxUploadControl.ShowAddRemoveButtons property is enabled. In this case, the ASPxUploadControl.FileInputCount property value is synchronized with actual number of file input elements after the most recent postback to the server.
The UploadedFiles property is used to access an array of automatically generated UploadedFile objects which are associated with file input elements. For each file input element, there is the corresponding UploadedFile entry within the UploadedFiles array. An individual UploadedFile object can be accessed via its index, which corresponds to the associated file input element’s visual index (it is assumed that file input element indexes are zero-based).
Note
We recommend that you use the UploadedFiles property only in the FileUploadComplete and FilesUploadComplete event handlers because this property may contain invalid data outside these events.
Example
This sample demonstrates how files selected within the ASPxUploadControl can be uploaded via either postback or callback, and how the uploaded files can be saved on the server side by using the FilesUploadComplete event.
View Example
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using DevExpress.Web.ASPxUploadControl;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e){
}
protected void ASPxUploadControl1_FilesUploadComplete(object sender, DevExpress.Web.ASPxUploadControl.FilesUploadCompleteEventArgs e){
// Intentionally pauses server-side processing to demonstrate the Loading Panel or Progress Panel functionality
System.Threading.Thread.Sleep(2000);
ASPxUploadControl uploadControl = sender as ASPxUploadControl;
if (uploadControl.UploadedFiles != null && uploadControl.UploadedFiles.Length > 0){
for (int i = 0; i < uploadControl.UploadedFiles.Length; i++){
UploadedFile file = uploadControl.UploadedFiles[i];
if (file.FileName != ""){
string fileName = string.Format("{0}{1}", MapPath("~/Images/"), file.FileName);
//file.SaveAs(fileName, true);//OnLine Demo Restriction
}
}
}
}
}
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register Assembly="DevExpress.Web.v11.1, Version=11.1.2.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a"
Namespace="DevExpress.Web.ASPxUploadControl" TagPrefix="dx" %>
<%@ Register Assembly="DevExpress.Web.ASPxEditors.v11.1, Version=11.1.2.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a"
Namespace="DevExpress.Web.ASPxEditors" TagPrefix="dx" %>
<%@ Register Assembly="DevExpress.Web.v11.1, Version=11.1.2.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a"
Namespace="DevExpress.Web.ASPxLoadingPanel" TagPrefix="dx" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<script type="text/javascript">
function UpdateUploadButton() {
var isAnyFileSelected = false;
for (var i = 0; i < uploadControl.GetFileInputCount(); i++) {
if (uploadControl.GetText(i) != "") { isAnyFileSelected = true; break; }
}
btnUploadViaPostback.SetEnabled(isAnyFileSelected);
btnUploadViaCallback.SetEnabled(isAnyFileSelected);
}
</script>
<dx:ASPxLabel ID="lblAllowebMimeType" runat="server" Text="Allowed image types: jpeg, png">
</dx:ASPxLabel>
<br />
<dx:ASPxUploadControl ID="ASPxUploadControl1" runat="server" Width="400px"
ClientInstanceName="uploadControl" ShowAddRemoveButtons="True"
OnFilesUploadComplete="ASPxUploadControl1_FilesUploadComplete"
ShowProgressPanel="True" > <%-- Progress Panel is in effect in callback mode only. --%>
<ValidationSettings AllowedFileExtensions=".jpg, .png">
</ValidationSettings>
<ClientSideEvents
Init="function(s, e) { UpdateUploadButton(); }"
TextChanged="function(s, e) { UpdateUploadButton(); }"
FilesUploadComplete="function(s, e) { UpdateUploadButton(); }"
FileUploadStart="function(s, e) {
btnUploadViaPostback.SetEnabled(false);
btnUploadViaCallback.SetEnabled(false);
}" />
</dx:ASPxUploadControl>
<br />
<dx:ASPxButton ID="ASPxButton1" runat="server" Width="150px"
AutoPostBack="True" Text="Upload via postback" ClientInstanceName="btnUploadViaPostback">
<ClientSideEvents Click="function(s, e) { loadingPanel.Show(); }" /> <%-- Button click shows a loading panel and generates a postback. --%>
</dx:ASPxButton>
<br />
<dx:ASPxButton ID="ASPxButton2" runat="server" Width="150px"
AutoPostBack="False" Text="Upload via callback" ClientInstanceName="btnUploadViaCallback" >
<ClientSideEvents Click="function(s, e) { uploadControl.Upload(); }" /> <%-- Button click initiates upload via a callback. Progress panel is displayed automatically. --%>
</dx:ASPxButton>
<br />
<%-- Loading Panel is used in this sample to visualize uploads performed via postbacks --%>
<dx:ASPxLoadingPanel ID="ASPxLoadingPanel1" runat="server"
ContainerElementID="ASPxUploadControl1" ClientInstanceName="loadingPanel">
</dx:ASPxLoadingPanel>
</form>
</body>
</html>
<%@ Page Language="vb" AutoEventWireup="true" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<%@ Register assembly="DevExpress.Web.ASPxEditors.v11.1, Version=11.1.1.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" namespace="DevExpress.Web.ASPxEditors" tagprefix="dx" %>
<%@ Register assembly="DevExpress.Web.v11.1, Version=11.1.1.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" namespace="DevExpress.Web.ASPxLoadingPanel" tagprefix="dx" %>
<%@ Register assembly="DevExpress.Web.v11.1, Version=11.1.1.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" namespace="DevExpress.Web.ASPxUploadControl" tagprefix="dx" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<script type="text/javascript">
function UpdateUploadButton() {
var isAnyFileSelected = false;
for (var i = 0; i < uploadControl.GetFileInputCount(); i++) {
if (uploadControl.GetText(i) != "") { isAnyFileSelected = true; break; }
}
btnUploadViaPostback.SetEnabled(isAnyFileSelected);
btnUploadViaCallback.SetEnabled(isAnyFileSelected);
}
</script>
<dx:ASPxLabel ID="lblAllowebMimeType" runat="server" Text="Allowed image types: jpeg, png">
</dx:ASPxLabel>
<br />
<dx:ASPxUploadControl ID="ASPxUploadControl1" runat="server" Width="400px"
ClientInstanceName="uploadControl" ShowAddRemoveButtons="True"
OnFilesUploadComplete="ASPxUploadControl1_FilesUploadComplete"
ShowProgressPanel="True" > <%-- Progress Panel is in effect in callback mode only. --%>
<ValidationSettings AllowedFileExtensions=".jpg, .png">
</ValidationSettings>
<ClientSideEvents
Init="function(s, e) { UpdateUploadButton(); }"
TextChanged="function(s, e) { UpdateUploadButton(); }"
FilesUploadComplete="function(s, e) { UpdateUploadButton(); }"
FileUploadStart="function(s, e) {
btnUploadViaPostback.SetEnabled(false);
btnUploadViaCallback.SetEnabled(false);
}" />
</dx:ASPxUploadControl>
<br />
<dx:ASPxButton ID="ASPxButton1" runat="server" Width="150px"
AutoPostBack="True" Text="Upload via postback" ClientInstanceName="btnUploadViaPostback">
<ClientSideEvents Click="function(s, e) { loadingPanel.Show(); }" /> <%-- Button click shows a loading panel and generates a postback. --%>
</dx:ASPxButton>
<br />
<dx:ASPxButton ID="ASPxButton2" runat="server" Width="150px"
AutoPostBack="False" Text="Upload via callback" ClientInstanceName="btnUploadViaCallback" >
<ClientSideEvents Click="function(s, e) { uploadControl.Upload(); }" /> <%-- Button click initiates upload via a callback. Progress panel is displayed automatically. --%>
</dx:ASPxButton>
<br />
<%-- Loading Panel is used in this sample to visualize uploads performed via postbacks --%>
<dx:ASPxLoadingPanel ID="ASPxLoadingPanel1" runat="server"
ContainerElementID="ASPxUploadControl1" ClientInstanceName="loadingPanel">
</dx:ASPxLoadingPanel>
</form>
</body>
</html>
Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports DevExpress.Web.ASPxUploadControl
Partial Public Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
End Sub
Protected Sub ASPxUploadControl1_FilesUploadComplete(ByVal sender As Object, ByVal e As DevExpress.Web.ASPxUploadControl.FilesUploadCompleteEventArgs)
' Intentionally pauses server-side processing to demonstrate the Loading Panel or Progress Panel functionality
System.Threading.Thread.Sleep(2000)
Dim uploadControl As ASPxUploadControl = TryCast(sender, ASPxUploadControl)
If uploadControl.UploadedFiles IsNot Nothing AndAlso uploadControl.UploadedFiles.Length > 0 Then
For i As Integer = 0 To uploadControl.UploadedFiles.Length - 1
Dim file As UploadedFile = uploadControl.UploadedFiles(i)
If file.FileName <> "" Then
Dim fileName As String = String.Format("{0}{1}", MapPath("~/Images/"), file.FileName)
'file.SaveAs(fileName, True)'OnLine Demo Restriction
End If
Next i
End If
End Sub
End Class
The following code snippet (auto-collected from DevExpress Examples) contains a reference to the UploadedFiles property.
Note
The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.
See Also