Hello there,
my Blazor WASM application needs to work on a .xls file that is chosen from the user.
I've tried to use a RadzenFileInput for the file selection but I couldn't find the way to access the chosen file, work on it and then save on the user machine.
Do you have any suggestion to accomplish that?
Hi @Temozat,
You need to bind the Value of RadzenFileInput - it will contain the base64 encoded data of the file.
<RadzenFileInput @bind-Value="@data" />
@code {
string data;
}
Keep in mind there are size restrictions though and it could fail for larger files. In that cases we recommend using RadzenUpload which posts the file to a controller.
Thanks for the help.
I have one more question about the FileInput:
I made the component not visible, cause I want to simulate the click on the "Choose" button every time that I click on a specific component (a RadzenCard in my case). I've defined the function associated ad the onclick of the RadzenCard like this:
private async Task OpenFileInput()
{
await JSRuntime.InvokeAsync<object>("eval", "document.getElementById('fileInput').click();");
}
where fileInput is the ElementReference binded to the RadzenFileInput,
but that doesn't work. How can I accomplish this?
Most probably there is no HTML element with such id. Inspect the rendered DOM tree with your browser developer tools.
Thet's how I defined the FileInput:
<RadzenFileInput id="fileInput" ref="@inputFile" @bind-Value="@excelFile" @bind-FileSize="@fileSize" TValue="string" Visible=false Change=@(args => OnFileSelected(args)) />
I don't think invoking the click method of the DOM element would open the file browser dialog as is considered a security risk. You need to think of a different approach.