0

I'm using the Xam.Plugin.FilePicker NUGet version 1.1.0 on a Xamarin.Android.Support.v4 Fragment and when I use the file picker it works fine but when I get a file the byte array is empty and the file name is only the name of the file without the path.

If only I could get the file's full path it would be great, from there I could get the byte array. I am doing something wrong? my code is like this:

try
{
    var crossFilePicker = Plugin.FilePicker.CrossFilePicker.Current;
    var myResult = await crossFilePicker.PickFile();
    if (!string.IsNullOrEmpty(myResult.FileName)) //Just the file name, it doesn't has the path
    {
        foreach (byte b in myResult.DataArray) //Empty array
            b.ToString();
    }
}
catch (InvalidOperationException ex)
{
    ex.ToString(); //"Only one operation can be active at a time"
}

Also if you use the back button it won't let you pick andother file because "Only one operation can be active at a time"

2 Answers2

1

for "Path" you should download the GitHub code that has this property. Nuget package is a bit old

Alessandro Caliaro
  • 5,623
  • 7
  • 27
  • 52
1

I have tested the file picker plugin for xamarin forms android. It can get the file byte, I can output the file bytes. Your code is right please check what the file type you selected or you may selected an error file. In my site, I selected a jpg file:

enter image description here

If only I could get the file's full path it would be great

You can not get the file path now, but this function will coming soon. Please check the github repository commit branch.

Also if you use the back button it won't let you pick andother file because "Only one operation can be active at a time"

This issue is also fixed on the way, please check the github repository

If you can not wait for them to fix, I suggest you to download the source code and change it by yourself.

Mike Ma
  • 2,017
  • 1
  • 12
  • 17
  • I downloaded the code but still had an error when getting the path, checking the code I found in IOUtil.class a TODO to handle non-primary volumes... adding the exact same code "return Android.OS.Environment.ExternalStorageDirectory + "/" + split [1];" fixed the path and it is working fine now, I will put this observation also in the gitpage, thanks! – Cristopher Garza Mar 17 '17 at 18:50