Back to Devexpress

IFileInputSelectedFile.Name Property

blazor-devexpress-dot-blazor-dot-ifileinputselectedfile.md

latest1.9 KB
Original Source

IFileInputSelectedFile.Name Property

Returns the file name.

Namespace : DevExpress.Blazor

Assembly : DevExpress.Blazor.v25.2.dll

NuGet Package : DevExpress.Blazor

Declaration

csharp
string Name { get; }

Property Value

TypeDescription
String

The file name.

|

Remarks

To introduce secure file upload operations to your application, you should always validate the file name. You can perform the following actions:

  • Check the name length.
  • Check that the name contains only allowed characters.
  • If you save the file to a real file system, check whether the result file path is within the expected root directory. Call the Path.GetFullPath method to resolve path information.

The following example gets names of uploaded files:

razor
<DxFileInput FilesUploading="OnFilesUploading" />

@code {
    async Task OnFilesUploading(FilesUploadingEventArgs args) {
        foreach (var file in args.Files) {
            // Do not rely on or trust the name without validation.
            var name = file.Name;
            /* The following code is intended for demonstration purposes only.
            Do not read a stream directly in memory to avoid performance and security-related issues. */
            using var stream = new System.IO.MemoryStream();
            await file.OpenReadStream(file.Size).CopyToAsync(stream);
        }
    }
}

See Also

IFileInputSelectedFile Interface

IFileInputSelectedFile Members

DevExpress.Blazor Namespace