Maui FilePicker based on Microsoft.maui.storage.filepicker. which can read/write picked file after applicationr retart,pick folder and create file/folder under it. only support android,windows.
$ dotnet add package CommonDialogs.MauiI cannot find possibility to select file or folder for MAUI application. I can only found library which support file and folder selection for windows and android. So I based this package on that library.
Note: At this time supported file and folder operations under windows and android only. I don't have any apple devices so I cannot test possible additions now
Don't forget to change android manifest and set permissions
for android api bigger as 29 you need to add
Note 1: After file selection absolute path under android could be not correct so it is better to use platform path instead Note 2: Write to external storage from api 30 (Andorid 11) or for some android devices is not possible in easy way.
It is possible to call supported opearations over static call or over dependecy injection (DI).
If you want to use DI add services.AddFileSystemOperations(); and use something like this
@inject IFileSystemOperations CommonOperations
FilePickResult res = await CommonOperations.PickFileAsync(FilePickOptions.Videos);
using var stream = CommonOperations.OpenFile(res.PlatformPath, FileOperations.Read);
...
var results = await CommonOperations.PickFilesAsync(FilePickOptions.Videos);
var fileOptions = new FilePickOptions()
{
FileTypes = new FilePickerFileType(new Dictionary>
{
{DevicePlatform.Android, new string[]{"image/*"} },
{DevicePlatform.WinUI, new string[]{"*.png", "*.jpg", "*.jpeg", "*.webp","*.gif","*.bmp"} }
}),
};
FilePickResult res = await CommonOperations.PickFileAsync(fileOptions);
var folder = await CommonOperations.PickFolderAsync(null);
var res = CommonOperations.CreateFile(folder.PlatformPath, "test.txt");
using var stream = CommonOperations.OpenFile(res.PlatformPath, FileOperations.Write);
using var sw = new StreamWriter(stream );
sw.Write("Some text");
var res3 = CommonOperations.CreateFolder(folder.PlatformPath, "testFolder");
var res4 = CommonOperations.CreateFile(res3.PlatformPath, "TestInnerFolder/test.txt");
using var stream = CommonOperations.OpenFile(res4.PlatformPath, FileOperations.Write);
using var sw = new StreamWriter(stream);
sw.Write("Some text");
In repository you can find sample project too
If you have problem for writing to SD card for android with platform path too, try this solution: Open system settings and go to Apps. Find application named Files (on some devices the app may have name Documents or other name). You may need to enable to show system apps from menu. You may also filter to show only disabled apps, then you may find it easier. Then enable the app, force-close X-plore and retry.
This is reported to fix the problem, if Documents (Files) app exists on device. If the app is not included, there may be no fix.
Dialog Title is not changeable/visible. Behavior is different per platform.
Icons inspiration by Icons8