How to get Project Root Path

NapZoomNapZoom CAMember ✭✭

In my project I have a file called "Assets/abc.bak" that I want to copy to /data/data/com.myapp/files

I tried
File.Copy("./Assets/abc.bak", "/data/data/com.myapp/files/abc.bak");
File.Copy("Assets/abc.bak", "/data/data/com.myapp/files/abc.bak");

I get an error saying can't find "./Assets/abc.bak". My question is how do I copy the file "Assets/abc.bak" to "/data/data/com.myapp/files"?


  • JonathanPryorJonathanPryor USXamarin Team Xamurai

    I assume that Assets/abc.bak is an AndroidAsset? Assets are not stored as distinct files; they are stored as entries within the .apk file (which is a ZIP container).

    You need to use the Assets API to obtain the Asset stream, and then copy it out:

    string destPath = Path.Combine(
    using (var source = activity.Assets.Open("abc.bak"))
    using (var dest = File.OpenWrite(destPath))
  • NapZoomNapZoom CAMember ✭✭

    Thank you. Worked like a charm.

Sign In or Register to comment.