Abhishek Bagchi
Abhishek Bagchi

Reputation: 23

How to give option to user for choosing the file folder in xamarin forms?

I would like to give user an ability to chose the desired file location in his/her device to save information. I didn't find anything on the Internet that would work for all the platforms. The only options seem to be available for Android.

Upvotes: 1

Views: 1012

Answers (2)

Lucas Zhang
Lucas Zhang

Reputation: 18861

You can use the package Xamarin.Plugin.FilePicker from NuGet. It is a FilePicker Plugin for Xamarin.Forms.

Example:

try
{
   FileData fileData = await CrossFilePicker.Current.PickFile();
   if (fileData == null)
       return; // user canceled file picking

   string fileName = fileData.FileName;
   string contents = System.Text.Encoding.UTF8.GetString(fileData.DataArray);

   System.Console.WriteLine("File name chosen: " + fileName);
   System.Console.WriteLine("File data: " + contents);
}
catch (Exception ex)
{
   System.Console.WriteLine("Exception choosing file: " + ex.ToString());
}

For iOS ,you need to Configure iCloud Driver for your app.For more detail and if you want download a sample you can refer here.

Upvotes: 2

Guilherme Marques
Guilherme Marques

Reputation: 495

For IOS you can read this document.

https://possiblemobile.com/2013/04/using-xcode-to-test-location-services/

All,( android and IOS ) can be manipulated by dependency injection. So you are using native code of android and of IOS and choose/control in xamarin forms.

Good luck

Guilherme

Upvotes: 0

Related Questions