Android:
Android groups the filesystem into two different types of storage: Internal Storage, External Storage.
Internal Storag: https://learn.microsoft.com/en-us/xamarin/android/platform/files/#working-with-internal-storage
You could use System.Environment.GetFolderPath()
to retrieve internal storage directory like below:
/data/user/0/com.companyname/files
External Storage: https://learn.microsoft.com/en-us/xamarin/android/platform/files/external-storage?tabs=windows
The directory of the private external files would be:
/storage/emulated/0/Android/data/com.companyname.app/files/
You could get it via dependency service.
DependencyService: https://learn.microsoft.com/en-us/xamarin/xamarin-forms/app-
fundamentals/dependency-service/introduction
Create an interface IExternalStorage:
public interface IExternalStorage
{
string GetPath();
}
The implementation on the Android:
[assembly:Dependency(typeof(AndroidImplementation))]
namespace App.Droid
{
public class AndroidImplementation: IExternalStorage
{
public string GetPath()
{
Context context = Android.App.Application.Context;
var filePath = context.GetExternalFilesDir("");
return filePath.Path;
}
}
}
Then you could use it in Xamarin.Forms:
var folderPath = DependencyService.Get<IExternalStorage>(). GetPath();
IOS:
Each iOS app has its own sandbox directory. https://developer.apple.com/library/archive/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/FileSystemOverview/FileSystemOverview.html
Generally, we store user's data in the Documents folder. And we could access its path on Forms directly:
var path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
Please note: IOS only could access photo gallery and iCloud folder.
File system access in Xamarin.iOS: https://learn.microsoft.com/en-us/xamarin/ios/app-fundamentals/file-system