It is a Blazor project
Below is the Index.razor:
//A file selector that returns only file name instead of full path
<InputFile id="flpicker" OnChange="@OnInputFileChange" multiple />
<p>@fileName</p> // displays file name that was picked (i.e.example1.json)
//below four line passes file name to JS
@{
var passFileName = @fileName;
}
<input type="hidden" id="PassingFileNameToJS" value=@passFileName>
@code{
string fileName;
//below function gets file name
private async Task OnInputFileChange(InputFileChangeEventArgs e)
{
foreach (var File in e.GetMultipleFiles(e.FileCount))
{
var Name = File.Name;
fileName = Name;
}
}
}
Below is the index.js: Full path of file selected.
var filePath= "file:///C:/JsonFiles/" + document.getElementById("PassingFileNameToJS").value;
'document.getElementById("PassingFileNameToJS")' provides file name "example1.json". But in order to get full path, I hard to hardcode values.
When I use this above full filepath for opening file, throws error as "Not allowed to load local resource: file:///C:/JsonFiles/example1.json".
Is it possible to get full path without hardcoding values like above? Any help would be appreciated.