I am looking to get the path to a file in my .net Maui app. I have set the file 'Build Action' to MauiAsset and 'Copy to Output Directory' to Copy if newer.
When deploying to Windows I can successfully get the path by using:
string fileName = $"{AppDomain.CurrentDomain.BaseDirectory}MyFolder\\myfile.txt";
which resolves as: "C:\Users\xxx\source\repos\myproject\myproject\bin\Debug\net6.0-windows10.0.19041.0\win10-x64\AppX\MyFolder\myfile.txt"
On android im trying to use:
string fileName = $"{AppDomain.CurrentDomain.BaseDirectory}/MyFolder/myfile.txt";
which resolves as: "/data/user/0/com.companyname.myproject/files/MyFolder/myfile.txt"
This is aparently not a usable path on android as the app then throws
System.IO.DirectoryNotFoundException: 'Could not find a part of the path '/data/user/0/com.companyname.myproject/files/MyFolder/myfile.txt'.'
when I try to access it using
System.IO.File.ReadAllLines(fileName);
It also looks like the start of the path is missing but how do I get that?