Search code examples
androidandroid-fragmentsxamarinnugetfilepicker

Xam.Plugin.FilePicker Works fine but can't get file


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"


Solution

  • 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.