0

My MauiBlazorApp can create a .pdf file. In what ways can I make this file accessible for the users of windows/android/IOS. A SaveFile Dialog is not yet implemented in Maui. With this path

string SaveToPath = System.IO.Path.Combine(FileSystem.Current.AppDataDirectory, "hello.pdf");

I can save it on a windows machine and open it (tested). The path (FileSystem.Current.AppDataDirectory) on a local android device (phone connected to windows maschine via usb) is something like this:

/data/user/0/com.companyname.appname/files/hello.pdf

But later I can't find this folder on my phone. I find this:

/data/com.companyname.appname/cache/ empty folders all the way

Why can't I save a file in .../downloads

How do you import/export data from 'device to device' in Maui? Files seems to be not the way. Email with attechments? Is that possible/better?

nogood
  • 1,117
  • 1
  • 11
  • 34

1 Answers1

1

You can check the Maui File picker, It provides the method you can pick the file from the device.

public async Task<FileResult> PickAndShow(PickOptions options)
{
    try
    {
        var result = await FilePicker.Default.PickAsync(options);
        if (result != null)
        {
            if (result.FileName.EndsWith("jpg", StringComparison.OrdinalIgnoreCase) ||
                result.FileName.EndsWith("png", StringComparison.OrdinalIgnoreCase))
            {
                using var stream = await result.OpenReadAsync();
                var image = ImageSource.FromStream(() => stream);
            }
        }

        return result;
    }
    catch (Exception ex)
    {
        // The user canceled or something went wrong
    }

    return null;
}

In addition, you can refer to Folder Picker .NET MAUI. This is more detailed.

Guangyu Bai - MSFT
  • 2,555
  • 1
  • 2
  • 8
  • I want to save a file on the device (all three, windows, android, ios) and later be able to find this file and work on this file outside of the app. Is your solution truly the way to go? I don't want to open the file with my app again! – nogood Dec 27 '22 at 08:22
  • 1
    Platform do not allow access to the common external folders. For example, starting in Android 11, apps that use the scoped storage model can access only their own app-specific cache files. apps cannot access the public file path. – Guangyu Bai - MSFT Jan 04 '23 at 05:16
  • Okay. So as I suggested/asked in orig. question a FileTransport via Email is a valid approach then to share data on different devices or is there a better way? – nogood Jan 05 '23 at 15:07
  • 1
    I think use the email might be better. – Guangyu Bai - MSFT Jan 06 '23 at 02:46