选择在 Xamarin Forms 中存储文件的路径 [英] Select path for storing file in Xamarin Forms
问题描述
我有一个 Xamarin 表单应用程序,我想保存文件,当用户在手机中打开文件管理器或手机连接到计算机时,应显示该文件.我读了这篇文章,但问题是该文件存储到 Environment.SpecialFolder.Personal
并且用户无法打开此路径.我还发现了这个 plugin,它的作用完全相同.它将文件存储到路径 Environment.SpecialFolder.Personal
.当我尝试将文件保存在另一个位置时,我总是收到错误消息:
I have a Xamarin form application and I want to save file and the file should be shown when user open file manager in his phone or when the phone is connected to computer. I read this article, but the problem is that the file is stored to Environment.SpecialFolder.Personal
and the user can't open this path. Also I found this plugin which does exactly the same thing. It store file to the path Environment.SpecialFolder.Personal
. And when I try to save file in another location, I always get error message says:
对路径.."的访问被拒绝
Access to the path '..' is denied
我应该使用哪个路径来保存文件?
Which path should I use to save file?
推荐答案
对于 Android,@David Moškoř 的答案完美运行.
For Android, the answer of @David Moškoř work perfectly.
对于IOS,我们可以使用如下路径:
For IOS, we can use the following path:
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "..", "Library");
但是LSSupportsOpeningDocumentsInPlace
和Supports Document Browser
必须在IOS项目的Info.plist
文件中开启,以便用户浏览保存的文件(当您打开 Files
应用程序并导航到 On My iPhone
时,它会出现)
but LSSupportsOpeningDocumentsInPlace
and Supports Document Browser
must be enabled in the Info.plist
file of IOS project in order to make user browse the saved file (It will appear when you open Files
app and navigate to On My iPhone
)
这篇关于选择在 Xamarin Forms 中存储文件的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!