Read file from Uno

Hi guys! I’m implementing Google styled maps in fuselibs but I have a problem reading a file from Uno. I have the style in this route

 - build/
   MainView.ux
   map_style.json
   map_test.unoproj

My question is How to read the file map_style.json from Uno? I already tried…

  var dataDirectory = Directory.GetUserDirectory(UserDirectory.Config);
  var filePath = Uno.IO.Path.Combine(dataDirectory, _fileName);
  
  return File.ReadAllText(filePath);

but it throws Uno.IO.IOException: Couldn't open file: /map_style.json

Someone can help me?

Hey!

If you are including the file as a bundle in your unoproj, you can use this to read the text file to a string:

string text = Bundle.Get(@(PACKAGE)).GetFile(filename).ReadAllText();

Check out bundlefile if you are interrested in other ways of reading from a bundle file. (Make sure to click “Show advanced things”)

Thanks Liam! Is there way to get the file without the bundle like Image does? I’m trying to add the file this way:

{
  "RootNamespace":"",
  "Packages": [
    "Fuse",
    "Fuse.Maps",
    "FuseJS"
  ],
  "Includes": [
    "*"
  ],
  "Android": {
     "Geo": {
          "ApiKey": "AIzaSyDZi7TSWSdVO8O2H-i30p1_zUmasSRGyLE"
      },
      "MapStyle" : "map_style.json"
  }
}
extern (Android) static class ForeignHelpers
{
	internal static string _fileName = extern<string>"uString::Ansi(\"@(Project.Android.MapStyle:Or(''))\")";

	[Foreign(Language.Java)]
	internal static Java.Object CreateMap()
	@{
		String style = @{readMapStyle():Call()};
		FuseMap map = new FuseMap();

		map.setMapStyle(style);
		return map;
	@}

	internal static string readMapStyle()
	{
		var dataDirectory = Directory.GetUserDirectory(UserDirectory.Config);
		var filePath = Uno.IO.Path.Combine(dataDirectory, _fileName);

		return File.ReadAllText(filePath);
	}