Back to Devexpress

ASPxFileManager.FileUploading Event

aspnet-devexpress-dot-web-dot-aspxfilemanager-bafc39ba.md

latest3.8 KB
Original Source

ASPxFileManager.FileUploading Event

Fires on the server side before a file is uploaded, and allows you to cancel the action.

Namespace : DevExpress.Web

Assembly : DevExpress.Web.v25.2.dll

NuGet Package : DevExpress.Web

Declaration

csharp
public event FileManagerFileUploadEventHandler FileUploading
vb
Public Event FileUploading As FileManagerFileUploadEventHandler

Event Data

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

PropertyDescription
CancelGets or sets a value indicating whether the action that raised the event should be canceled. Inherited from FileManagerActionEventArgsBase.
ErrorTextGets or sets a text for the explanatory message. Inherited from FileManagerActionEventArgsBase.
FileGets a file, related to the event.
FileNameGets or sets the name of a file selected to upload.
InputStreamGets a stream object that points to the uploaded file.
OutputStreamGets a stream object that points to the uploaded file.

Remarks

Before each time a file is uploaded on the server side, the FileUploading event occurs, allowing you to cancel the file upload. The event parameter’s FileManagerFileUploadEventArgs.File property identifies the file that is being processed. To cancel the upload operation, set the FileManagerActionEventArgsBase.Cancel property to true. In order to show the message, explaining the reason for the upload cancellation, specify the FileManagerActionEventArgsBase.ErrorText property.

Example

The code below allows end-users to upload only mp3 files to the “Music mp3” folder.

csharp
protected void ASPxFileManager1_FileUploading(object source, DevExpress.Web.FileManagerFileUploadEventArgs e) {
      if (e.File.Folder.FullName == "Files\\Music mp3")
            if (e.File.Extension != ".mp3") {
                e.Cancel = true;
                e.ErrorText = "You can only upload mp3 files to this folder";
            }
}
aspx
<dx:ASPxFileManager ID="ASPxFileManager1" runat="server" OnFileUploading="ASPxFileManager1_FileUploading">
            <Settings RootFolder="~/Content/FileManager/Files" ThumbnailFolder="~\Thumb" />
</dx:ASPxFileManager>

See Also

SettingsUpload

FileUploading

FileUploaded

File Manager

ASPxFileManager Class

ASPxFileManager Members

DevExpress.Web Namespace