InfernumDeus
InfernumDeus

Reputation: 1202

How to get asset file path in Xamarin?

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?

Upvotes: 1

Views: 11984

Answers (3)

InfernumDeus
InfernumDeus

Reputation: 1202

Looks like it's impossible.

Closest solution is to write file to Cache.

Upvotes: 0

Mabrouk MAHDHI
Mabrouk MAHDHI

Reputation: 104

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.. :)

Upvotes: 1

Stefan Wanitzek
Stefan Wanitzek

Reputation: 2124

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.

Upvotes: 3

Related Questions