Example E4552
Visible to All Users

Upload Control for ASP.NET Web Forms - How to limit the number of uploaded files

When the EnableMultiSelect property is set to true, ASPxUploadControl allows users to choose multiple files to upload in a single open file dialog. This example demonstrates how to limit the number of files that a user can upload at once.

Files to Review

Documentation

Example Code

WebSite/Default.aspx
ASPx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <%@ Register Assembly="DevExpress.Web.v13.1, Version=13.1.14.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web" TagPrefix="dx" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>How to limit the number of uploaded files</title> <style type="text/css"> .groupBox { width: 319px; height: 206px; } </style> </head> <body> <script type="text/javascript"> var filesNumber; var msg = 'Too many files'; function textChanged(s, e) { filesNumber = upload1.GetText().split(',').length; if (filesNumber > spinEdit.GetValue()) alert(msg); } function uploadStart(s, e) { if (filesNumber > spinEdit.GetValue()) { alert(msg); e.cancel = true; } } function fileUploadComplete(s, e) { if (e.callbackData != "") addFileToContainer(e.callbackData); } function addFileToContainer(callbackData) { var label = document.createElement('label'); label.innerText = callbackData; var fileContainer = document.getElementById("groupBox1"); fileContainer.appendChild(label); fileContainer.appendChild(document.createElement('br')); } </script> <form id="form1" runat="server"> <div> <dx:ASPxSpinEdit ID="ASPxSpinEdit1" runat="server" Number="5" Height="19px" ClientInstanceName="spinEdit" HelpText="Files count" Width="86px" /> <dx:ASPxUploadControl ID="ASPxUploadControl1" runat="server" Width="280px" ShowAddRemoveButtons="true" ShowUploadButton="true" ShowProgressPanel="true" ClientInstanceName="upload1" OnFileUploadComplete="ASPxUploadControl1_FileUploadComplete"> <ClientSideEvents TextChanged="textChanged" FileUploadStart="uploadStart" FileUploadComplete="fileUploadComplete" /> <ValidationSettings MaxFileSize="4000000"></ValidationSettings> <AdvancedModeSettings EnableMultiSelect="true" /> </dx:ASPxUploadControl> <br /> <fieldset class="groupBox" id="groupBox1"> <legend>Uploaded Files</legend> </fieldset> </div> </form> </body> </html>

Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.