1

I have data.xlsx file in Assets folder and need to get its path to apply some library.

Found several solutions here but neither works for me. For example - File Not Found Exception In Xamarin program

I tried to use file:///android_asset/data.xlsx but here is no file too.

I checked the path with: System.IO.File.Exists(filePath);

So how to get path to this file? Maybe I have to place it in different folder?

Update: possibly I can solve it this way: java.io.FileNotFoundException: This file can not be opened as a file descriptor; it is probably compressed

But I can't find where to place it.

Update: this question is about Java and this is unclear how to use this solution in Xamarin.Android: How to get the android Path string to a file on Assets folder?

Arialdo Martini
  • 4,427
  • 3
  • 31
  • 42
InfernumDeus
  • 1,185
  • 1
  • 11
  • 33

3 Answers3

3

Looks like the file isn't included in the APK. Ensure that the Build Action of the file in the Asset-folder is set to AndroidAsset.

Stefan Wanitzek
  • 2,059
  • 1
  • 15
  • 29
1

in general using Xamarin.android , you can use this code :

private string _fileName {get;set;}

      public string FileFullPath
      {
         get
          {
            return Path.Combine(Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryPictures),_fileName);
          }
      }

Hope it helps.. :)

  • Can i somehow refer to any different directory than `Android.OS.Environment.DirectoryPictures`? My file is input data so this sounds a bit inappropriate. – InfernumDeus Sep 11 '16 at 06:35
  • 1
    `Android.OS.Environment.GetExternalStoragePublicDirectory` is now deprecated – Uzair Ali Jun 10 '20 at 12:10
0

Looks like it's impossible.

Closest solution is to write file to Cache.

InfernumDeus
  • 1,185
  • 1
  • 11
  • 33