Can't write file in USB flash drive with Xamarin Android/Uwp

我的未来我决定 提交于 2019-12-11 18:45:24

问题


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

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.

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

/storage/[NameOfTheFlashDrive]

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

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

Same message > System.UnauthorizedAccessException Access to the path

I don't know how to proceed.

I have used =

File.WriteAllText(filePath, Data);

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

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.

Thank you. Zebiphire.


回答1:


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.

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



来源:https://stackoverflow.com/questions/55127363/cant-write-file-in-usb-flash-drive-with-xamarin-android-uwp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!