Reputation: 13
With the coming .net5.0 I have started learning blazor. I want to convert a project. The problem is file upload.
I need to allow users to upload images and small data files.
I am using these examples
<InputFile id="uploadFolder" OnChange="HandleSelection" />
@code {
IFileListEntry[] selectedFiles;
void HandleSelection(IFileListEntry[] files)
{
selectedFiles = files;
}
}
Error CS0246 The type or namespace name 'IFileListEntry' could not be found (are you missing a using directive or an assembly reference?) WebApplication6.Client G:\ Blazor\WebApplication6\WebApplication6\Client\Pages\Index.razor 11 Active
Upvotes: 1
Views: 4621
Reputation: 14533
You are using the wrong docs. That was the prototype used I believe for 5.0. Please use the latest documentation.
Your code should look something like this now:
<InputFile multiple OnChange="HandleSelection" />
@code {
IReadOnlyList<IBrowserFile> selectedFiles;
void HandleSelection(InputFileChangeEventArgs eventArgs)
{
const int MaxAllowedFiles = 5;
selectedFiles = eventArgs.GetMultipleFiles(MaxAllowedFiles);
}
}
Upvotes: 3