net maui folderpicker on iOS, return a path with access denied

Alessandro Caliaro 4,196 Reputation points
2023-07-16T04:42:42.2533333+00:00

I am using FolderPicker to have a path where I can create a file.

on Android it returns a path that I can write to (till A10...)

in iOS it returns a path where I can't create a file. I have always "access denied".

Am I doing something wrong?

There are some permission I have to set on iOS to write a file?

Developer technologies .NET .NET MAUI
0 comments No comments
{count} votes

Accepted answer
  1. Anonymous
    2023-07-17T07:55:54.9166667+00:00

    Hello,

    You cannot write files to this path by code directly.

    If you want to write a file in the Files application in iOS platform.

    Firstly, Enable iCloud capabilities. For more information, see Capabilities.

    And Enable Share with Files app.

    Then, if I have an image that in the /Resources/Image folder, I want to write it to the Files application

    • Firstly, we can copy it to the application internal storage.
    public async Task CopyFileToAppDataDirectory(string filename)
        {
            // Open the source file
            using Stream inputStream = await FileSystem.Current.OpenAppPackageFileAsync(filename);
    
           // Create an output filename
            string targetFile = Path.Combine(FileSystem.Current.AppDataDirectory, filename);
           // Copy the file to the AppDataDirectory
            using FileStream outputStream = File.Create(targetFile);
            await inputStream.CopyToAsync(outputStream);
        }
    
    • Second, we can share this file to Files app. It will push a popup window, please choose Save to Files selection.
    public async Task ShareFile()
        {
            string fn = "test.png";
            string file = Path.Combine(FileSystem.Current.AppDataDirectory, fn);
            await Share.Default.RequestAsync(new ShareFileRequest
            {
                Title = "Share text file",
                File = new ShareFile(file)
            });
        }
    

    Best Regards,

    Leon Lu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.