Ticket T159966
Visible to All Users

ASPxUploadControl - How to get input indexes for uploaded files on the server side in MulitFile Upload scenario in Advanced mode (for BC2637, BC2645, BC2646, BC2647)

created 10 years ago (modified 10 years ago)

This ticket contains a workaround for BC2637. The BC2637 breaking change occurred in versions 12.2.18+ (and recent 12.2.17 hotfixes), 13.1.12+ (recent 13.1.11 hotfixes), 13.2.12+ and 14.1.8+.

Answers approved by DevExpress Support

created 10 years ago (modified 10 years ago)

This workaround is relevant only in versions where the breaking change occurred and will not work in earlier versions.

You can use ASPxHiddenField to store input indexes for each file to be uploaded inside the FileUploadStart client event handler as shown below:

ASPx
<html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server">     <title></title>     <script type="text/javascript">         function uploaderOnFileUploadStart(s, e) {             var fileIndex = -1;             for(var inputIndex = 0; inputIndex < uploader.GetFileInputCount(); inputIndex++) {                 var inputText = uploader.GetText(inputIndex);                 if(inputText) {                     fileIndex++;                     var mapKey = "index_" + fileIndex;                     hfInputFileMap.Set(mapKey, inputIndex);                 }             }         }         function uploaderOnFilesUploadComplete(s, e) {             var data = e.callbackData.split('|'),                 fileContainer = document.getElementById("fileContainer");             fileContainer.innerHTML = "";             for(var i = 0; dataItem = data[i]; i++)                 fileContainer.innerHTML += dataItem + "<br />";         }     </script> </head> <body>     <form id="form1" runat="server">         <div>             <dx:ASPxHiddenField ID="hfInputFileMap" runat="server" ClientInstanceName="hfInputFileMap" />             <dx:ASPxUploadControl ID="UploadControl" runat="server" ClientInstanceName="uploader" Width="300"                 UploadMode="Advanced" FileUploadMode="OnPageLoad" ShowUploadButton="True" ShowProgressPanel="true"                 FileInputCount="3" ShowAddRemoveButtons="true"                 OnFilesUploadComplete="UploadControl_FilesUploadComplete">                 <AdvancedModeSettings EnableMultiSelect="false" />                 <ClientSideEvents FilesUploadComplete="uploaderOnFilesUploadComplete"                     FileUploadStart="uploaderOnFileUploadStart" />                 <ValidationSettings AllowedFileExtensions=".gif,.jpg,.jpeg,.png" MaxFileSize="1000000">                 </ValidationSettings>             </dx:ASPxUploadControl>             <br /><br />Uploaded files:             <div id="fileContainer">             </div>         </div>     </form> </body> </html>

After that you can get input indexes for each uploaded file inside the FilesUploadComplete server event handler as follows:

C#
protected void UploadControl_FilesUploadComplete(object sender, FilesUploadCompleteEventArgs e) {        for(int fileIndex = 0; fileIndex < UploadControl.UploadedFiles.Length; fileIndex++) {            UploadedFile file = UploadControl.UploadedFiles[fileIndex];            if(string.IsNullOrEmpty(file.FileName) || !file.IsValid)                continue;            string mapKey = "index_" + fileIndex;            object inputIndexValue = hfInputFileMap[mapKey];            int inputIndex = int.Parse(inputIndexValue.ToString());            string fileString = string.Format("FileIndex = {0}, InputIndex = {1}, FileInfo = '{2} ({3}B)'", fileIndex, inputIndex, file.FileName, file.ContentLength);            e.CallbackData += fileString + "|";        }    }

Attached is a sample project which illustrates this approach.
.

    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.