无法使用 Xamarin Android/Uwp 在 USB 闪存驱动器中写入文件 [英] Can't write file in USB flash drive with Xamarin Android/Uwp

查看:42
本文介绍了无法使用 Xamarin Android/Uwp 在 USB 闪存驱动器中写入文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一些麻烦.这是关于这个主题 => System.UnauthorizedAccessException :访问路径/storage/[Name]/[nameFolder]/[fileName].txt 被拒绝.在 System.IO.FileStream 等......

I have some troubles. It's about this subject => System.UnauthorizedAccessException : Access to the path "/storage/[Name]/[nameFolder]/[fileName].txt is denied. At System.IO.FileStream etc….

我知道这个主题已经在 SOF 中,但我找不到 Xamarin.Android 的解决方案.Xamarin.Uwp 也是一样,没有访问权限.

I know this subject is already here in SOF, but I can't find a solution for Xamarin.Android. It's the same for Xamarin.Uwp, no access right.

我无法在根路径中写入文件(来自 U 盘路径)​​=

I can't write a file in the root path (from the USB Flash Drive path) =

/storage/[NameOfTheFlashDrive]

/storage/[NameOfTheFlashDrive]

如果我使用Android路径也是一样=

It's the same if I use the Android path =

content://com.android.externalstorage.documents/documents/[NameOfTheFlashDrive]

content://com.android.externalstorage.documents/documents/[NameOfTheFlashDrive]

相同消息 > System.UnauthorizedAccessException 访问路径

Same message > System.UnauthorizedAccessException Access to the path

我不知道如何继续.

我用过 =

File.WriteAllText(filePath, Data);

File.WriteAllText(filePath, Data);

而且我有在外部存储中写入文件的权限.

And I have the permissions to write file in external storage.

唯一的解决方案是使用Plugin.EssentialPickerFile 并手动保存在正确的路径中.

The only solution is to use Plugin.Essential or PickerFile and save manually in the correct path.

如果有人想以正确的方式继续.

If someone have a idea to proceed with the right way.

谢谢.Zebiphire.

Thank you. Zebiphire.

推荐答案

我遇到了一些麻烦.这是关于这个主题 => System.UnauthorizedAccessException :对路径/storage/[Name]/[nameFolder]/[fileName].txt 的访问被拒绝.在 System.IO.FileStream 等......

I have some troubles. It's about this subject => System.UnauthorizedAccessException : Access to the path "/storage/[Name]/[nameFolder]/[fileName].txt is denied. At System.IO.FileStream etc….

根据您的错误信息,我猜您可能需要在运行时启用权限.

According to your error message, I guess that you ma need to enbale permission in runtime.

您应该在 Android 和 UWP 中启用 READ_EXTERNAL_STORAGEWRITE_EXTERNAL_STORAGE 权限.

You should enable READ_EXTERNAL_STORAGE and WRITE_EXTERNAL_STORAGE permissions in Android and UWP.

这篇关于无法使用 Xamarin Android/Uwp 在 USB 闪存驱动器中写入文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆