Xamarin forms, OSM file, system IO File not found exception

Hi I am having trouble with some file handling in Xamarin forms. Each time I run my code I keep getting the systemIO FileNotfound exception. The code I am using is below. The stuff about routerDB is part of a pathfinding NuGet package I am using called Itinero. Before my code can even reach the create routerDb.LoadOsmData line it keeps getting stuck at line 4 and returning the error: System.IO.FileNotFoundException: ‘Could not find file “/Datewales-latest.osm.pbf”‘

Here is the the absolute path of that file “wales-latest.osm.pbf” in Xamarin forms.

C:USW PathfinderUSW PathfinderUSW PathfinderbinDebugDate

I was so frustrated this did not work that I created another program but this time a windows forms one and I entered the same code as below and it worked first time flawlessly and created me the file wales.router.db as I expected.

Here is the absolute path of that file “wales-latest.osm.pbf” in Windows forms.

C:UsersMYNAMEDesktopPathfinderPathfinderbinDebugDate

I have also tried simpler file handling code in Xamarin forms to see if I can reach any file as shown in the second code block and I am always met with file not found.

Please can anyone suggest why this would be?

 private void LoadButton_OnClicked(object sender, EventArgs e)
    { 
        var routerDb = new RouterDb();
        using (var stream = new FileInfo(@"Datewales-latest.osm.pbf").OpenRead())
        {
            // create the network for cars.
            routerDb.LoadOsmData(stream, Vehicle.Car);
        }

        // write the routerdb to disk.
        using (var stream = new FileInfo(@"wales.routerdb").Open(FileMode.Create))
        {
            routerDb.Serialize(stream);
        };
    }
public void ReadButton_OnClicked(object sender, EventArgs e)
        {
              File.ReadAllText(@"Datewales-latest.osm.pbf");

        }

Answer

c: is a folder on YOUR PC. Xamarin is running on a mobile device (or emulator) and at runtime it does not have access to your PC’s filesystem. If you want to include a file as part of your application, you need to include as part of your project so that it is deployed with your app

Xamarin docs have entire writeup on working with files