CommonDialogs.Maui
1.0.10
dotnet add package CommonDialogs.Maui --version 1.0.10
NuGet\Install-Package CommonDialogs.Maui -Version 1.0.10
<PackageReference Include="CommonDialogs.Maui" Version="1.0.10" />
paket add CommonDialogs.Maui --version 1.0.10
#r "nuget: CommonDialogs.Maui, 1.0.10"
// Install CommonDialogs.Maui as a Cake Addin #addin nuget:?package=CommonDialogs.Maui&version=1.0.10 // Install CommonDialogs.Maui as a Cake Tool #tool nuget:?package=CommonDialogs.Maui&version=1.0.10
CommonDialogs.MAUI
Overview
I 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
Supported operations
- Create file
- Select single file
- Select many files
- Open file
- Create folder
- Select folder
Android permissions
Don't forget to change android manifest and set permissions
- READ_EXTERNAL_STORAGE
- WRITE_EXTERNAL_STORAGE
for android api bigger as 29 you need to add
- MANAGE_EXTERNAL_STORAGE
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.
Samples
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
- Select a video file and read it:
FilePickResult res = await CommonOperations.PickFileAsync(FilePickOptions.Videos);
using var stream = CommonOperations.OpenFile(res.PlatformPath, FileOperations.Read);
...
- Select many video files:
var results = await CommonOperations.PickFilesAsync(FilePickOptions.Videos);
- Select special types of file:
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);
- Select a folder and create file under it:
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");
- Select a folder and create subfolder with file:
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
Troubleshooting
Android: write to external storage
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
Dialog Title is not changeable/visible. Behavior is different per platform.
- iOS & Windows don't seem to use the title at all
- macOS does
- On Android I think it might show when you get the popup to pick an app to pick your actual file. So then it will only show when you have multiple apps installed that can pick a file. If there is only 1 app installed then it will skip that dialog and you'll never see the title. This is due to the nature of Android where you can have a multitude of apps to complete your actions.
Usefull links
Icons inspiration by Icons8
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0-android31.0 is compatible. net6.0-ios16.1 is compatible. net6.0-maccatalyst16.1 is compatible. net6.0-windows10.0.19041 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-windows was computed. net8.0-android was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-windows was computed. |
-
net6.0-android31.0
- No dependencies.
-
net6.0-ios16.1
-
net6.0-maccatalyst16.1
-
net6.0-windows10.0.19041
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.0.10 | 406 | 8/20/2023 |