Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
EricRosenfeld1 authored Nov 1, 2019
1 parent 2dca662 commit 878d973
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,36 @@
This is a prototype for a file input component that may be added to Blazor in the future.

For installation and usage information, see [this blog post](http://blog.stevensanderson.com/2019/09/13/blazor-inputfile/).

## Using a custom <input> button with MatBlazor:

```csharp
<MatButton OnClick="@(() => OnButtonClick("myInput"))" Label="Choose File"></MatButton>
<InputFile HideElement="true" OnChange="HandleFileSelected" ElementId="myInput"> </InputFile>

@if (file != null)
{
<p>Name: @file.Name</p>
<p>Size in bytes: @file.Size</p>
<p>Last modified date: @file.LastModified.ToShortDateString()</p>
<p>Content type (not always supplied by the browser): @file.Type</p>
}

@code {

public async void OnButtonClick(string elementID)
{
await JSRuntime.InvokeAsync<string>("BlazorInputFile.wrapInput", elementID);
}

IFileListEntry file;

void HandleFileSelected(IFileListEntry[] files)
{
file = files.FirstOrDefault();
}

}
```

Reference from [here](https://stackoverflow.com/a/9546968)

0 comments on commit 878d973

Please sign in to comment.