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.