CommonDialogs.Maui 1.0.10

dotnet add package CommonDialogs.Maui --version 1.0.10                
NuGet\Install-Package CommonDialogs.Maui -Version 1.0.10                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="CommonDialogs.Maui" Version="1.0.10" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add CommonDialogs.Maui --version 1.0.10                
#r "nuget: CommonDialogs.Maui, 1.0.10"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// 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

  1. Select a video file and read it:
FilePickResult res = await CommonOperations.PickFileAsync(FilePickOptions.Videos);
using var stream = CommonOperations.OpenFile(res.PlatformPath, FileOperations.Read);
...
  1. Select many video files:
var results = await CommonOperations.PickFilesAsync(FilePickOptions.Videos);
  1. 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);
  1. 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");
  1. 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.

Maui issue

Icons inspiration by Icons8

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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 440 8/20/2023