So, I used <input>
tag and input an xml file from the user. Now I want to read the content of the file. I want to be able to save the content as a JSON Object. This will be of the type IBrowserFile but I am not sure how can I use this to iterate over the file and fetch the data. If there is some other way to do so please let me know.
Sample html written is:
<input type="file" onchange="@LoadFile" accept=".xml" />
Please help me finding a solution for this!
CodePudding user response:
You can get a stream:
async Task LoadFile(InputFileChangeEventArgs e)
{
var stream = e.File.OpenReadStream();
var doc = await XDocument.LoadAsync(stream, ...);
// process your data
}
Note that Microsoft does not recommend this kind of in-memory operations, estimate your risks.