Back to Devexpress

ASPxClientUploadControl.FileUploadComplete Event

aspnet-js-aspxclientuploadcontrol-8fca118f.md

latest6.1 KB
Original Source

ASPxClientUploadControl.FileUploadComplete Event

Occurs on the client side after a file has been uploaded.

Declaration

ts
FileUploadComplete: ASPxClientEvent<ASPxClientUploadControlFileUploadCompleteEventHandler<ASPxClientUploadControl>>

Event Data

The FileUploadComplete event's data class is ASPxClientUploadControlFileUploadCompleteEventArgs. The following properties provide information specific to this event:

PropertyDescription
callbackDataGets a string that contains specific information (if any) passed from the server side for further client processing.
errorTextGets the error text to be displayed within the ASPxUploadControl ‘s error frame.
inputIndexGets the index of a file input element within the ASPxUploadControl.
isValidGets or sets a value indicating whether the uploaded file passes validation.

Remarks

Write the FileUploadComplete event handler to perform specific client actions after a file has been uploaded to a server. If several files have been selected for upload, the FileUploadComplete event fires for each of them. After all files have been uploaded, the ASPxClientUploadControl.FilesUploadComplete event fires.

Note

When you use Azure, the FileContent and FileBytes properties have no effect in a FileUploadComplete event handler.

Online Examples

View Example: Upload Control for ASP.NET Web Forms - How to upload an image and display it on a web page

View Example: Grid View for ASP.NET MVC - How to upload an Excel file using an upload control and display the file's data in the grid

Limitation

  • When you use Azure, the FileContent and FileBytes properties have no effect in a FileUploadComplete event handler.

Example

aspx
<script type="text/javascript">
     function onFileUploadStart(s, e) {
          DXUploadedFilesContainer.Clear();
     }
     function onFileUploadComplete(s, e) {
          if(e.callbackData) {
               var fileData = e.callbackData.split('|');
               var fileName = fileData[0],
                    fileUrl = fileData[1],
                    fileSize = fileData[2];
               DXUploadedFilesContainer.AddFile(fileName, fileUrl, fileSize);
          }
     }
</script>
    ...
<dx:ASPxUploadControl ID="UploadControl" runat="server" ClientInstanceName="UploadControl" Width="100%"
     NullText="Select multiple files..." UploadMode="Advanced" ShowUploadButton="True" ShowProgressPanel="True"
     OnFileUploadComplete="UploadControl_FileUploadComplete">
     <AdvancedModeSettings EnableMultiSelect="True" EnableFileList="True" EnableDragAndDrop="True" />
     <ValidationSettings MaxFileSize="4194304" AllowedFileExtensions=".jpg,.jpeg,.gif,.png">
     </ValidationSettings>
     <ClientSideEvents FilesUploadStart="onFileUploadStart" FileUploadComplete="onFileUploadComplete" />
</dx:ASPxUploadControl>

<dx:UploadedFilesContainer ID="FileContainer" runat="server" Width="100%" Height="180" 
     NameColumnWidth="240" SizeColumnWidth="70" HeaderText="Uploaded files" />
csharp
const string UploadDirectory = "~/UploadControl/UploadImages/";

protected void UploadControl_FileUploadComplete(object sender, FileUploadCompleteEventArgs e) {
     string resultExtension = Path.GetExtension(e.UploadedFile.FileName);
     string resultFileName = Path.ChangeExtension(Path.GetRandomFileName(), resultExtension);
     string resultFileUrl = UploadDirectory + resultFileName;
     string resultFilePath = MapPath(resultFileUrl);
     //Save the uploaded file
     e.UploadedFile.SaveAs(resultFilePath);
     string name = e.UploadedFile.FileName;
     string url = ResolveClientUrl(resultFileUrl);
     long sizeInKilobytes = e.UploadedFile.ContentLength / 1024;
     string sizeText = sizeInKilobytes.ToString() + " KB";
     e.CallbackData = name + "|" + url + "|" + sizeText;
}
vb
Private Const UploadDirectory As String = "~/UploadControl/UploadImages/"

Protected Sub UploadControl_FileUploadComplete(ByVal sender As Object, ByVal e As FileUploadCompleteEventArgs)
     Dim resultExtension As String = Path.GetExtension(e.UploadedFile.FileName)
     Dim resultFileName As String = Path.ChangeExtension(Path.GetRandomFileName(), resultExtension)
     Dim resultFileUrl As String = UploadDirectory & resultFileName
     Dim resultFilePath As String = MapPath(resultFileUrl)
     'Save the uploaded file
     e.UploadedFile.SaveAs(resultFilePath)
     Dim name As String = e.UploadedFile.FileName
     Dim url As String = ResolveClientUrl(resultFileUrl)
     Dim sizeInKilobytes As Long = e.UploadedFile.ContentLength / 1024
     Dim sizeText As String = sizeInKilobytes.ToString() & " KB"
     e.CallbackData = name & "|" & url & "|" & sizeText
End Sub

See Also

FilesUploadComplete

Page Life Cycle During File Upload

ASPxClientUploadControl Class

ASPxClientUploadControl Members