How to Open Files on Xamarin Android Using FilePicker
Ronald GANS
136
Reputation points
using Xamarin.Essentials; (at the top of the file)
async Task<FileResult> PickAndShow(PickOptions options)
{
try
{
var result = await FilePicker.PickAsync(options);
if (result != null)
{
string Text = $"File Name: {result.FileName}";
if (result.FileName.EndsWith("jpg", StringComparison.OrdinalIgnoreCase) ||
result.FileName.EndsWith("png", StringComparison.OrdinalIgnoreCase))
{
var stream = await result.OpenReadAsync();
Image = ImageSource.FromStream(() => stream);
}
}
return result;
}
catch (Exception ex)
{
// The user canceled or something went wrong
}
return null;
}
But I get this error:
The name FilePicker does not exist in the current context.
There are several other similar errors.
Any help is very appreciated.
Developer technologies | .NET | Xamarin
5,381 questions
Sign in to answer