AppDataDirectory, FilePicker, reading and writing files.
App File System Paths
// Private app data — persistent, backed up by Android
var dataPath = FileSystem.AppDataDirectory;
// Cache — may be cleared by the system to reclaim space
var cachePath = FileSystem.CacheDirectory;
// Write a text file
var filePath = Path.Combine(dataPath, "notes.txt");
await File.WriteAllTextAsync(filePath, "Hello from MAUI!");
// Read it back
var content = await File.ReadAllTextAsync(filePath);
FilePicker
var result = await FilePicker.PickAsync(new PickOptions
{
PickerTitle = "Select a document",
FileTypes = FilePickerFileType.Pdf
});
if (result is not null)
{
using var stream = await result.OpenReadAsync();
// process stream...
}
Picking Photos
var photo = await MediaPicker.Default.PickPhotoAsync();
if (photo is not null)
{
var stream = await photo.OpenReadAsync();
ImageView.Source = ImageSource.FromStream(() => stream);
}
Key Takeaways
AppDataDirectory is private to your app and persists across updates
CacheDirectory can be cleared by Android to reclaim storage space
FilePicker lets users select arbitrary files; MediaPicker targets images/video
Always copy photos to AppDataDirectory if you need them to persist