Xamarin Forms how to Save a file to a location where it can be copied off of the original device

你离开我真会死。 提交于 2020-03-04 18:04:16

问题


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.

Something to keep in mind:

  • It needs to work on all supported Xamarin Forms platforms - UWP, Android, iOS and Mac.
  • The app itself does not required the device to have a network connection.
  • The file needs to be savable in a place where the user can access / copy it to another device (i.e. a USB drive, a network share etc.)

What I have tried:

  • I have tried using the FilePicker plug in but could not get it to save to anywhere outside the application. (A user trying to find the folder here would not be easy.) Saving anyplace else I received an Access Denied error.
  • I have tried using the System.IO namespace but encountered the same Access Denied error when saving the file to a someplace outside the application.

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?


回答1:


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.



来源:https://stackoverflow.com/questions/59935478/xamarin-forms-how-to-save-a-file-to-a-location-where-it-can-be-copied-off-of-the

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