When try to pick up the file all files are showing as disable. I am unable select the files. I am using below code.
var options = new PickOptions
{
PickerTitle = "Please select a pdf file",
FileTypes = FilePickerFileType.Pdf
};
var fileResult = await FilePicker.PickAsync(options);
var file = await Constants.ValidateFileNew(fileResult);
if (file.IsValid )
{
var fileName = file.FileName;
var data = file.fileData;
Stream stream = new MemoryStream(data);
fileID += 1;
ListNursingAssessmentFileNames.Add(new FileEntity { FileName = fileName, FileID = fileID, File = data });
DependencyService.Get<IJsonFileService>().SaveToLibrary<ObservableCollection<FileEntity>>(ListNursingAssessmentFileNames, "NursingInitialAssessmentFiles.json");
stackDigitalForm.IsVisible = false;
}
I have provide exteral storage permission. Storage Permission SS
1条答案
按热度按时间tjrkku2a1#
You need specify custom files types when creating the PickOptions and they can be customized per platform.
Per docs ,
PickOptions.FileTypes
has many types in each platform,On Android and iOS the files not matching this list is only displayed grayed out. When the array is null or empty, all file types can be selected while picking. The contents of this array is platform specific; every platform has its own way to specify the file types. On Android you can specify one or more MIME types, e.g. "image/png"; also wild card characters can be used, e.g. "image/*". On iOS you can specify UTType constants, e.g. UTType.Image. On UWP, specify a list of extensions, like this: ".jpg", ".png".
You can refer to the following sample code:
I add a button to trigger the selection event,
Note:Don't forget to add
WRITE_EXTERNAL_STORAGE
andRAED_EXTERNAL_STORAGE
in your manifest file.Official reference docs: https://learn.microsoft.com/en-us/xamarin/essentials/file-picker?context=xamarin%2Fxamarin-forms&tabs=android