Xamarin Forms如何将文件保存到可以从原始设备复制出文件的位置 [英] Xamarin Forms how to Save a file to a location where it can be copied off of the original device

查看:552
本文介绍了Xamarin Forms如何将文件保存到可以从原始设备复制出文件的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Xamarin表单应用要求用户先进行一定数量的配置,然后才能使用它.此外,该应用程序可以由同一用户在多台计算机上运行(这样做有正当的商业理由.)我想做的是将应用程序的配置备份到一个文件中,然后可以在该文件上使用该文件.另一台设备以完全相同的方式在新设备上自动配置应用程序.这样可以防止用户在希望运行该应用程序的每台设备上重新输入所有配置信息.

My Xamarin forms app required the user to perform a certain amount of configuration before it can be used. Additionally, the app can be run on multiple computers by the same user (There are valid business reasons for doing this.) What I would like to be able to do is backup the configuration of the app to a file that can then be used on another device to automatically configure the app on the new device in exactly the same way. This will prevent the users from re-entering all the configuration information on each device where they wish to run the app.

需要注意的地方:

  • 它需要在所有受支持的Xamarin Forms平台上工作-UWP,Android,iOS和Mac.
  • 该应用程序本身不需要该设备具有网络连接.
  • 该文件需要在用户可以访问/将其复制到其他设备(例如USB驱动器,网络共享等)的地方保存

我尝试过的事情:

  • 我尝试使用FilePicker插件,但无法将其保存到应用程序之外的任何位置. (试图在这里找到该文件夹​​的用户并不容易.)将其保存在其他位置时,我收到访问被拒绝"错误.
  • 我尝试使用System.IO命名空间,但是在将文件保存到应用程序之外的某个位置时遇到了相同的拒绝访问"错误.

我想我的最后一招是在XF编辑器控件等中显示配置信息,或者将其复制到剪贴板(如果可能),然后让用户手动将数据保存到应用程序外部的文件中.有人对如何处理有其他建议吗?

I guess my last resort would be to display the configuration information in a XF editor control or such or just copy it to the clipboard (if possible) and have the user manually save the data to a file outside of the application. Does anyone have any other suggestions on how this can be handled?

推荐答案

因此,在尝试了多种方法并研究了可能的解决方案之后,我找不到轻松实现此目的的方法.相反,我使用Xamarin Essentials剪贴板功能并将文件内容复制到剪贴板.然后,我向用户显示一条消息,告诉他们将剪贴板内容粘贴到文件中.这似乎是我目前能做的最好的事情.

So after trying multiple things and looking at possible solutions, I could not find a way to easily do this. Instead I used the Xamarin Essentials clipboard function and copied the contents of the file into the clipboard. I then display a message to the user telling them to past the clipboard contents into a file. This seemed to be the best I could do for now.

这篇关于Xamarin Forms如何将文件保存到可以从原始设备复制出文件的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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