0

I'm using Xamarin for developing my application. I saw a lot of answers but didn't find something which can help me. How can I get the path to the application's files folder which is situated in sdcard0? I want to get something like that: /storage/sdcard0/Android/data/[MyApplication]/files.

I did the following:

var path = Environment.GetFolderPath(Environment.SpecialFolder.Personal);

It gives me "/data/data/App1.Droid/files" but it is not I'm looking for.

Joseph Katzman
  • 1,959
  • 6
  • 21
  • 47
  • I am using Android Studio, maybe you could try `Environment.getExternalStorageDirectory().getAbsolutePath()` – Rust Fisher Apr 10 '17 at 09:54
  • use `getCanonicalPath()`. see [this](http://stackoverflow.com/questions/11488754/whats-the-difference-between-canonicalpath-and-absolutepath) accpet my comment as answer! ;D – Mehran Zamani Apr 10 '17 at 10:21

1 Answers1

1
// this for your application directory 
System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal)



// for external storage 
File path = Android.OS.Environment.getExternalStoragePublicDirectory(
            Environment.DIRECTORY_PICTURES);

Reference

Update

Note : to call System.Environment => you need to be in droid application cant be called in PCl

to call Android.OS.Environment => you need to reference mono.android in your PCl or called in direct in your droid application

Mina Fawzy
  • 20,852
  • 17
  • 133
  • 156
  • I use Xamarin framework and C# language. Unfortunately, there is no API which provides your method. You can see this link https://developer.xamarin.com/api/type/Android.OS.Environment/ This part of code `Android.OS.Environment.GetExternalStoragePublicDirectory("files");` gives me `"/storage/sdcard0/files"`, but I need my application folder also. – Joseph Katzman Apr 10 '17 at 13:43
  • 1
    if you call this method in your droid application it will work just fine , but if you called in PCl (first you cant call System.Environment , Second you need reference mono android to call Android.OS.Environment ) – Mina Fawzy Apr 10 '17 at 14:50