Xam.Plugin.FilePicker正常工作,但无法获取文件 [英] Xam.Plugin.FilePicker Works fine but can't get file
问题描述
我在Xamarin.Android.Support.v4片段上使用Xam.Plugin.FilePicker NUGet版本1.1.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"
推荐答案
我已经测试了适用于xamarin形式android的文件选择器插件. 它可以获取文件字节,我可以输出文件字节.您的代码正确,请检查您选择的文件类型,否则您可能选择了错误文件.在我的网站上,我选择了一个jpg文件:
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:
如果只有我可以获取文件的完整路径,那就太好了
If only I could get the file's full path it would be great
您现在无法获取文件路径,但是此功能即将推出.请检查github存储库提交分支.
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.
这篇关于Xam.Plugin.FilePicker正常工作,但无法获取文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!