Search code examples
c#androidioswindows-phonexamarin.forms

How to allow app user to select a folder location where in app documents can be saved


I have a xamarin.forms app, I would like to allow users of app (android/ iOS/ windows) to be able to select a folder location at the start of the app and all the app related documents should be saved in that particular folder.

For now when I try to build a simple app which reads a xml file from the folder I create and display data on a list-view. I browsed through the file manager in android to see where the file is located physically on android device, but could not find any folder with app name.

In simple words I want a folder on the device to be created, which will be selected by the user. And accessible from file manager.

The reason behind this requirement is, the app is going to record a mp3 file and save a recording to a selected folder. So whenever the user wants to change his mobile he can always copy the recording to the new mobile and not loose any of the recordings.


Solution

  • To be able to use any of the possibilities below you will have to write platform-specific code in Xamarin.Forms and then expose some interface that you can use back in your PCL project.

    Android:-

    There is a post Choose File Dialog on how to create a file dialog selector (with directory changer), although not in Xamarin.

    You will want to point the starting location to a shared folder of some kind.

    There is a Xamarin tutorial here that walks you through how to create a simple file browser.

    iOS:-

    For iOS you may be interested in the iOS Document Picker View Controller, here.

    There is an extensive tutorial of how to complete this using Xamarin here.

    enter image description here

    (pictures are from Xamarin website)